Before starting the server, I need to export ('set' actualy, I'm using Win7) NODE_PATH variable. I tried to do it with this command (not working even in command line):
set NODE_PATH=./ && node server.js
and for package.json:
"scripts": {
"start": "set NODE_PATH=. && node server.js"
},
But it's not working. I got Error: Cannot find module
which appears only if NODE_PATH
not specified.
So, how this problem could be solved? I need a proper way to export NODE_PATH
and run the server with inline command, or a way to specify two separate commands for 'start' script.
npm start: npm start script is used to execute the defined file in it without typing its execution command. Package.json file "scripts"{ "start":"node index.js" } index.js.
set NODE_PATH=./ ; && node server.js
On Windows, the command above works fine. And in general, it should work without a semicolon when you set environment variables. But here, probably, path string causes the problem?
Also notice that you should set environment variables in a different way for Linux, no set
keyword must be used. If your scripts will be run on a different platform, probably it's better to use some plugin like cross-env to write your scripts.
This question helps Setting an environment variable before a command in Bash is not working for the second command in a pipe
Below is what worked for me in Linux (CentOS). I needed this because the node modules in use were all installed globally.
"scripts": {
"start": "export NODE_PATH=/usr/lib/node_modules && node myscript.js"
},
Use export instead of set. No semicolon needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With