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

383
Views
pass variable to npm command string (not the script run by npm command)

Is it possible to pass an argument to the npm command string? The info might be somewhere in docs, but brief digging didn't get me any results, moreover, it is probably beneficial to the large audience.

For example, i have a command build:docker in package.json:

   "scripts": {
      "build:docker": "tsc -b && sh dist.sh && docker build -t repo_name/image .",
   },

I want to pass the tag variable to the command string, ex:

"build:docker": "tsc -b && sh dist.sh && docker build -t repo_name/image:$tag ."

and run it as npm run build:docker --tag '1.0'.

Is something like this possible? Thanks!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Yes, you can: For example (for simplicity), for the line:

"build": "tsc --project "

You can start it like so:

npm run build ./src

This will start:

> tsc --project  "./src"

And another solution (I didn't see the point without glasses :) ), more suitable for you is to prefix the name of the parameter with $npm_config_, so your line should look like this:

"build:docker": "tsc -b && sh dist.sh && docker build -t repo_name/image:$npm_config_mytag ."

And then run it as:

npm run build:docker --mytag=1.0

Watch out for =

over 4 years ago · Santiago Trujillo 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!