Skip to content

Instantly share code, notes, and snippets.

@ivanleoncz
Created March 26, 2019 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivanleoncz/af102552db4c6bdd1456894de3c507da to your computer and use it in GitHub Desktop.
Save ivanleoncz/af102552db4c6bdd1456894de3c507da to your computer and use it in GitHub Desktop.
Simple Express.js app, using Template Engine (EJS).
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);
});
{
"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"
}
}
<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