If your getting errors like ‘cannot find module x’ when trying to start a nodejs server on windows then you probably have some code which is looking for node modules but they are not being found. This could be a number of reasons but node will look in the default folders for the module and then recursively up the directories appending ‘node_modules/’ and looking in there for the module. If it has no luck then it will look inside the directories specified in your NODE_PATH environment variable.
This is the error you might see if node cannot find your module.
Setting the NODE_PATH environment variable
Setting the NODE_PATH environment variable is different based upon your OS and the terminal your using to run node.
Then when you use require.(‘module_name’) in your code, node will then do a recursive search upwards appending node_modules dir (relative path if you have not used /, ./ or ../):
Then it will search the directories in your NODE_PATH (absolute path):
Set NODE_PATH using Windows & GitBash
You need to use the export command so it’s available to all processes not just inside the shell.
Set NODE_PATH using Windows & CMD
You need to use the SET command and absolute path to your node module folder(s).
There is more reading in the references below.