Skip to content

Instantly share code, notes, and snippets.

@cbetta
Last active November 4, 2018 14:21
Show Gist options
  • Save cbetta/f1e03724c697fa517604b697dad8b7d2 to your computer and use it in GitHub Desktop.
Save cbetta/f1e03724c697fa517604b697dad8b7d2 to your computer and use it in GitHub Desktop.
Week 2 - Packages and a little simple server
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<%= new Date().toLocaleString() %>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<%= name %>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
Hello World
</body>
</html>
npm init
npm install express --save
touch week2.app.js
npm install -g nodemon
nodemon week2.app.js
npm install ejs --save
const express = require('express')
const app = express()
const port = 3000
app.get('/', (request, response) => {
response.send('Hello World!')
})
const path = require('path')
app.get('/file', (request, response) => {
response.sendFile(path.join(__dirname + '/views/index.html'))
})
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs')
app.get('/date', (request, response) => {
response.render('date')
})
app.get('/hello/:name', (request, response) => {
response.render('hello', request.params)
})
app.listen(port, () => {
console.log("Server started")
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment