Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using npm commands to start NodeJS project with arguments

Tags:

node.js

npm

I am trying to create two separate npm commands to start my NodeJS project locally on the dev machine and in production mode. I want to be able to pass arguments to the machine separately to serve the right dependencies - which could be a CDN in production OR my local machine.

Here's what I am looking to have in package.json

"run": "node ./server/app.js", /* for running locally*/

"start": "node ./server/app.js", /* for running in production*/

If I try to call npm run - it creates this error:

npm ERR! npm run-script [<pkg>] <command>
npm ERR! not ok code 0

I also want to be able to send commandline argumentswhich would contain a URL.

like image 346
EternallyCurious Avatar asked Jan 25 '14 05:01

EternallyCurious


1 Answers

You are not doing it right.

To call custom scripts, you have to run

npm run-script run

Your package.json should have:

"scripts": {
    "start": "node ./server/app.js",
    "run": "node ./server/app.js"
}

See: https://npmjs.org/doc/cli/npm-run-script.html

like image 83
Ali Avatar answered Sep 24 '22 15:09

Ali