Last active
November 28, 2017 06:49
-
-
Save writingdeveloper/7b95456cb32e681e27fa54c3b30e456d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var path = require('path'); | |
var app = express(); | |
app.locals.pretty = true; | |
app.set('view engine', 'pug'); | |
app.set('views', path.join(__dirname, 'views')); | |
app.use(express.static(path.join(__dirname, 'public'))); | |
app.get('/template', function(req, res) { | |
res.render('temp', { | |
time: Date(), | |
title: 'Pug' | |
}); | |
}) | |
app.get('/', function(req, res) { | |
res.send('Hello home page'); | |
}); | |
app.get('/dynamic', function(req, res) { | |
var lis = ''; | |
for (var i = 0; i < 5; i++) { | |
lis = lis + '<li>coding</li>'; | |
} | |
var time = Date(); | |
var output = ` | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title></title> | |
</head> | |
<body> | |
Hello, Dynamic! | |
<ul> | |
${lis} | |
</ul> | |
${time} | |
</body> | |
</html>`; | |
res.send(output); | |
}); | |
app.get('/route', function(req, res) { | |
res.send('Hello Router, <img src="/route.png">') | |
}) | |
app.get('/login', function(req, res) { | |
res.send('<h1>Login please</h1>'); | |
}); | |
app.listen(3000, function() { | |
console.log('Conneted 3000 port!'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment