@rpichioli/

Rendering server data to EJS view in Express

Nodejs

NodeJS Express server working with EJS for views rendering simply some data from server to view

fork
loading
Files
  • index.js
  • views
  • package-lock.json
  • package.json

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.5727947459151312","path":"index.js","file":{"path":"index.js","content":{"asEncoding":{"base64":"Ly8gSW1wb3J0aW5nIGluc3RhbGxlZCBOUE0gbW9kdWxlcwpjb25zdCBleHByZXNzID0gcmVxdWlyZSgnZXhwcmVzcycpOwpjb25zdCBwYXRoID0gcmVxdWlyZSgncGF0aCcpOwoKLy8gVGhlIHNlcnZlcgpjb25zdCBhcHAgPSBleHByZXNzKCk7CgovLyBTZXR0aW5nICJfX2Rpcm5hbWUiCmNvbnN0IF9fZGlybmFtZSA9IHBhdGgucmVzb2x2ZShwYXRoLmRpcm5hbWUoJycpKTsKCi8vIFNldCBFSlMgdGVtcGxhdGUgRW5naW5lCmFwcC5zZXQoJ3ZpZXdzJywnLi92aWV3cycpOwphcHAuc2V0KCd2aWV3IGVuZ2luZScsJ2VqcycpOwoKLy8gQmFzZSBwYXRoCmFwcC51c2UoZXhwcmVzcy5zdGF0aWMocGF0aC5qb2luKF9fZGlybmFtZSwgJ3B1YmxpYycpKSk7CgovLyBSb3V0ZQphcHAuZ2V0KCcvJywgKHJlcSwgcmVzKSA9PiB7CglyZXMucmVuZGVyKAoJCSdmb3JtJywgCgkJeyAKCQkJdGl0bGU6ICJIZXkgSSdtIGZyb20gc2VydmVyISIsCgkJCXRleHQ6ICJUaGlzIGlzIGEgcGFnZSBidWlsdCB3aXRoIEVKUyIKCQl9CgkpOwp9KTsKCi8vIFR1cm5pbmcgc2VydmVyIG9uCmFwcC5saXN0ZW4oMzAwMCwgKCkgPT4gY29uc29sZS5sb2coJ0xpc3RlbmluZyB0byAzMDAwIHBvcnQnKSk7"},"asBuffer":null},"loaded":true}}
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 v10.16.0