Created
March 26, 2019 13:57
-
-
Save ivanleoncz/af102552db4c6bdd1456894de3c507da to your computer and use it in GitHub Desktop.
Simple Express.js app, using Template Engine (EJS).
This file contains 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 port = 3000; | |
var app = express(); | |
app.set('views', path.join(__dirname, 'views')); | |
app.set('view engine', 'ejs'); | |
app.get('/', function(req, res) { | |
res.render('index', {username: 'ivanleoncz'}); | |
}); | |
app.get('/username/:user_name', function(req, res) { | |
res.status(200); | |
res.set('Content-type', 'text/html'); | |
res.send('<h1>Hello, ' + req.params.user_name + '!</h1>'); | |
}); | |
app.listen(port, function() { | |
console.log("Server is running: http://localhost:%s", port); | |
}); |
This file contains 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
{ | |
"name": "simple_ws", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "MIT", | |
"dependencies": { | |
"ejs": "^2.6.1", | |
"express": "^4.16.4" | |
} | |
} |
This file contains 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
<html> | |
<head> | |
<title>INDEX</title> | |
</head> | |
<body> | |
<h1>Welcome to index, <%= username %>!</h1> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment