Error: Cannot find module 'ejs'
I had this exact same problem a couple of days ago and couldn't figure it out. Haven't managed to fix the problem properly but this works as a temporary fix:
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.
Install express locally
(npm install express
while in the project's root directory)
Your project depends on both express
and ejs
, so you should list them both as dependencies in your package.json
.
That way when you run npm install
in you project directory, it'll install both express
and ejs
, so that var express = require('express')
will be the local installation of express (which knows about the ejs
module that you installed locally) rather than the global one, which doesn't.
In general it's a good idea to explicitly list all dependencies in your package.json
even though some of them might already be globally installed, so you don't have these types of issues.
I my case, I just added ejs manually in package.json:
{
"name": "myApp"
"dependencies": {
"express": "^4.12.2",
"ejs": "^1.0.0"
}
}
And run npm install (may be you need run it with sudo) Please note, that ejs looks views directory by default