Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

391
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda