The error: cannot find module ‘express’ occurs when the “Express.js module is not installed in your project, or there’s an issue with your node_modules directory.”
How to fix the error
The easiest way to fix the error is to install express in your project using this command: npm install express –save. This command will install Express and add it to the node_modules directory, where Node.js looks for installed modules.
After installing, ensure that ‘express’ is listed in the dependencies section of your package.json file.
If you still face the error, the node_modules directory might become corrupted or incomplete. If you suspect this, try deleting the node_modules directory and the package-lock.json file, and then run: npm install
If you have installed Express globally (i.e., with npm install -g express), your project might not recognize it. Always install project-specific dependencies locally.
That’s it! Happy Coding!