简体   繁体   中英

How to create my own scripts in node.js

I am building an node application, 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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM