grandhi
grandhi

Reputation: 219

How to create my own scripts in node.js

I am building an nodeapplication, it has 3 environments names are development,testing and production. Each environment has their own hostnames and port numbers. like in the following way

{
"development":{
"host":"develop.com",
"port":"2000"
},
"testing":{
"host":"testing.com",
"port":"2001"
},
"production":{
"host":"production.com",
"port":"2002"
}
}

While running my node application, I used to pass environment name as a command argument. like

node server.js development
  (or)                       
node server.js production

Instead of running application manually along with environment name, I want to implement with node scripts, so I have tried in the following way.

package.json

{
  "developemnt":"node server.js development",
  "production":"node server.js production",
  "testing":"node server.js testing"
}

What I thought, Instead of node server.js development, I can run npm development. This way I have made it, but it's not working. Regarding this, I have read npm script documentaion, as per documentation It's not possible,so is there any way to implement this.

Thanks

Upvotes: 3

Views: 196

Answers (1)

victorkt
victorkt

Reputation: 14572

For scripts that are not "default scripts" (the ones listed here), you need to use the run parameter with npm:

npm run development

npm run testing

npm run production

More details here.

Upvotes: 4

Related Questions