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 in Node-js by kartik
• 30,930 points
311 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 by Niroj
• 67,020 points

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 in Node-js by Niroj
• 67,020 points
111 views
0 votes
1 answer

Error: Cannot find module 'mongodb'

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

answered Oct 15 in Node-js by Niroj
• 67,020 points
54 views
0 votes
1 answer

Error:npm throws error without sudo

Hello @kartik, This looks like a permissions issue ...READ MORE

answered Jul 8 in Node-js by Niroj
• 67,020 points
194 views
+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 in Laravel by Niroj
• 67,020 points
2,796 views
0 votes
1 answer

What is redirection in Laravel?

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

answered Mar 18 in Laravel by Niroj
• 67,020 points
333 views
0 votes
1 answer

How to install Laravel via composer?

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

answered Mar 23 in Laravel by Niroj
• 67,020 points
228 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 in Laravel by Niroj
• 67,020 points
3,462 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 in Node-js by Niroj
• 67,020 points
224 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 in Node-js by Niroj
• 67,020 points
1,696 views