Pranshu Pranshu - 25 days ago 8
Node.js Question

Express Framework error

I am very new to Node.js and learning about Express framework now a days.
But I am again stuck at an error which is so much irritating.
I am learning from a video tutorial in which I was learning how to use Template Engine 'EJS' and was making a very simple program peacefully until I met this Error.

TypeError: Cannot read property '_locals' of undefined
at EventEmitter.render
at G:\Docs\Node.js\app.js:6:9
at Layer.handle [as handle_request]
at next (G:\Docs\Node.js\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch
at Layer.handle [as handle_request]
at G:\Docs\Node.js\node_modules\express\lib\router\index.js:281:22
at Function.process_params
at next (G:\Docs\Node.js\node_modules\express\lib\router\index.js:275:10)
at expressInit

And my code is this :-

var express = require('express');

var app = express();
app.set('view engine', 'ejs');
app.set('views', __dirname, '/templates');
app.get('/', function(req, res) {
app.send("Welcome to the Homepage");
app.get('/profile/:name', function(req, res) {
console.log("Server is running ....");

I have created a profile.ejs file in template folder which is present in my current directory and I want that when I type
That profile page must be rendered and shown.

my Profile.ejs page is :

<!DOCTYPE html>


<h1>Welcome to the Profile !!</h1>


I can't find an exact answer elsewhere.

Answer Source

Try like this,

app.get('/profile/:name', function(req, res) {
   res.render('profile'); // see the change here for *res*