Error Cannot find module ejs

0 votes

Here is my code:

var express = require('express');

var app = module.exports = express.createServer();

// Configuration

app.configure(function(){
  app.use(express.bodyParser());
  app.use(app.router);
  app.use(express.static(__dirname + '/public'));
});

app.set('view engine', 'ejs');
app.set('view options', {
    layout: false
});

app.get('/', function(req, res) {
  res.render('index', {
    message : 'De groeten'
  });
});

app.listen(3000);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);

I'm getting error as:

Error: Cannot find module 'ejs'
    at Function._resolveFilename (module.js:317:11)
    at Function._load (module.js:262:25)
    at require (module.js:346:19)
    at View.templateEngine (/Users/niroj/local/node/lib/node_modules/express/lib/view/view.js:133:38)
    at Function.compile (/Users/niroj/local/node/lib/node_modules/express/lib/view.js:65:17)
    at ServerResponse._render (/Users/niroj/local/node/lib/node_modules/express/lib/view.js:414:18)
    at ServerResponse.render (/Users/niroj/local/node/lib/node_modules/express/lib/view.js:315:17)
    at /Users/niroj/Sites/soldhere.in/app.js:26:7
    at callbacks (/Users/niroj/local/node/lib/node_modules/express/lib/router/index.js:272:11)
    at param (/Users/niroj/local/node/lib/node_modules/express/lib/router/index.js:246:11

In my folder, I have ejs installed in node_modules which I got using npm install ejs.

 enter image description here

How to fix it?

Sep 7, 2020 in Node-js by kartik
• 37,520 points
10,522 views

1 answer to this question.

0 votes

Hello @kartik,

Go up one level (above app.js) and do npm install ejs. It will create a new node_modules folder and Express should find the module then.

Hope it helps!!

Thank you!!

answered Sep 7, 2020 by Niroj
• 82,840 points
I am also suffering from this question, Can you elaborate once again!!

Hello @Praveer,

Have you tried the above solution?

Related Questions In Node-js

0 votes
1 answer

Error:Cannot find module 'xmlhttprequest'

Hello @kartik, XMLHttpRequest is a built-in object in web ...READ MORE

answered Sep 7, 2020 in Node-js by Niroj
• 82,840 points
7,249 views
0 votes
1 answer

Error: Cannot find module 'mongodb'

Hello @kartik, The error you are getting indicates ...READ MORE

answered Oct 15, 2020 in Node-js by Niroj
• 82,840 points
13,355 views
0 votes
0 answers

Node.js Error: Cannot find module express

I have written a code for my ...READ MORE

May 9, 2022 in Node-js by Kichu
• 19,040 points
3,183 views
0 votes
1 answer
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
23,080 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
3,016 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,948 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
44,887 views
0 votes
1 answer

Error:Nodejs cannot find installed module on Windows

Hello @kartik, Add an environment variable called NODE_PATH and set ...READ MORE

answered Jul 15, 2020 in Node-js by Niroj
• 82,840 points
4,950 views
0 votes
1 answer

Error:NPM global install “cannot find module”

Hello @kartik, I got this error Error: Cannot find ...READ MORE

answered Jul 16, 2020 in Node-js by Niroj
• 82,840 points
16,493 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP