Node.JS: Engine EJS

João Saraiva
Apr 4, 2021

Embedded JavaScript templating (EJS)

Similar to express to install EJS in a repository use the command:

npm install ejs -save

Since the project that will be created will have a considered size lets use pastes to store the files and have a better organization in the project.

For the app.js use:
app.set(‘view engine’, ‘ejs’)- this will set the view engine as ejs.

For the index.js use:

var express = require(‘express’); var app = express();app.set(‘view engine’, ‘ejs’); app.get(‘/’,function(req,res){ res.render(“./home/index”);}); app.get(‘/registo’,function(req,res){ res.render(“./registo/form_registo”);}); app.listen(8080,function(){ console.log(“Servidor ativo no porto 8080”);});

--

--