Sometimes, we want to fix the "Error: Cannot find module ‘ejs’" error with Node.js.
In this article, we’ll look at how to fix the "Error: Cannot find module ‘ejs’" error with Node.js.
How to fix the "Error: Cannot find module ‘ejs’" error with Node.js?
To fix the "Error: Cannot find module ‘ejs’" error with Node.js, we can install the ejs package.
To install it, we run
npm i ejs
Then we use it with
const ejs = require('ejs');
//...
app.set('view engine','ejs');
app.engine('ejs', require('ejs').__express);
to require the ejs module and call app.set to set the view engine to ejs.
And we call app.engine with define the ejs view engine by require the module and returning the __express property.
Conclusion
To fix the "Error: Cannot find module ‘ejs’" error with Node.js, we can install the ejs package.