Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

387
Views
node packge.json scripts - add command to existing script

I'd like to add a command to the "start" script so when I do npm start, first thing that will run is npm install.

My package.json looks as follows:

.
.
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "DEBUG=my-app node src/index.js",
    "dev": "nodemon src/index.js"
  },
.
.
.

I thought about adding npm install inside the start script:

   "start": "npm install DEBUG=my-app node src/index.js",

But this doesn't work so I'd like to get a suggestion, wether if it's even possible..

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I think you only use the && conector. like:

  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "npm install && DEBUG=my-app node src/index.js",
    "dev": "nodemon src/index.js"
  }
about 4 years ago · Juan Pablo Isaza Report

0

Andy yes, my app should be deployed once with a single command.

This is a quite a heavy/slow start, installing all modules before starting the app.

That means if I change the code somewhwere in my node server, stop the process and run it again, a full install is gonna happen. I realize that you have a dev script with nodemon, but still.

Another case: If your app crashes on the live server and you need to start it up again then a full install will happen. What happens if a module has gone up a patch or a minor version. That means you will start up a project with different dependencies.

If you're doing this in the ci/cd then a pipeline is usually split up:

  1. Install - npm ci
  2. Build/compile - for example if you have typescript (not in your case)
  3. Run all tests
  4. Remove the devDependencies with npm prune
  5. Start up the process

What you would maybe do is have a script called "pipeline" or something, and then call that.

"pipeline": npm ci && npm run build && npm test && npm prune && npm start

This script would then be called in your pipeline code.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!