Files
  • index.js
  • views
  • package-lock.json
  • package.json
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Importing installed NPM modules
const express = require('express');
const path = require('path');

// The server
const app = express();

// Setting "__dirname"
const __dirname = path.resolve(path.dirname(''));

// Set EJS template Engine
app.set('views','./views');
app.set('view engine','ejs');

// Base path
app.use(express.static(path.join(__dirname, 'public')));

// Route
app.get('/', (req, res) => {
	res.render(
		'form', 
		{ 
			title: "Hey I'm from server!",
			text: "This is a page built with EJS"
		}
	);
});

// Turning server on
app.listen(3000, () => console.log('Listening to 3000 port'));
node v9.7.1 linux/amd64