Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9165713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:58:14+00:00 2026-06-17T14:58:14+00:00

The scripts portion of my package.json currently looks like this: "scripts": { "start": "node

  • 0

The scripts portion of my package.json currently looks like this:

"scripts": {
    "start": "node ./script.js server"
}

…which means I can run npm start to start the server. So far so good.

However, I would like to be able to run something like npm start 8080 and have the argument(s) passed to script.js (e.g. npm start 8080 => node ./script.js server 8080). Is this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:58:16+00:00Added an answer on June 17, 2026 at 2:58 pm

    npm 2 and newer

    It’s possible to pass args to npm run since npm 2 (2014). The syntax is as follows:

    npm run <command> [-- <args>]

    Note the -- separator, used to separate the params passed to npm command itself, and the params passed to your script. (This is a common convention used by various command line tools).

    With the example package.json:

    "scripts": {
        "grunt": "grunt",
        "server": "node server.js"
    }
    

    here’s how to pass the params to those scripts:

    npm run grunt -- task:target  // invokes `grunt task:target`
    npm run server -- --port=1337 // invokes `node server.js --port=1337`
    

    Note: If your param does not start with - or --, then having an explicit -- separator is not needed; but it’s better to do it anyway for clarity.

    npm run grunt task:target     // invokes `grunt task:target`
    

    Note below the difference in behavior (test.js has console.log(process.argv)): the params which start with - or -- are passed to npm and not to the script, and are silently swallowed there.

    $ npm run test foobar
    ['C:\\Program Files\\nodejs\\node.exe', 'C:\\git\\myrepo\\test.js', 'foobar']
    
    $ npm run test -foobar
    ['C:\\Program Files\\nodejs\\node.exe', 'C:\\git\\myrepo\\test.js']
    
    $ npm run test --foobar
    ['C:\\Program Files\\nodejs\\node.exe', 'C:\\git\\myrepo\\test.js']
    
    $ npm run test -- foobar
    ['C:\\Program Files\\nodejs\\node.exe', 'C:\\git\\myrepo\\test.js', 'foobar']
    
    $ npm run test -- -foobar
    ['C:\\Program Files\\nodejs\\node.exe', 'C:\\git\\myrepo\\test.js', '-foobar']
    
    $ npm run test -- --foobar
    ['C:\\Program Files\\nodejs\\node.exe', 'C:\\git\\myrepo\\test.js', '--foobar']
    

    The difference is clearer when you use a param actually used by npm:

    $ npm test --help      // this is disguised `npm --help test`
    npm test [-- <args>]
    
    aliases: tst, t
    

    To get the parameter value, see this question. For reading named parameters, it’s probably best to use a parsing library like yargs or minimist; nodejs exposes process.argv globally, containing command line parameter values, but this is a low-level API (whitespace-separated array of strings, as provided by the operating system to the node executable).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script we use. What I need a portion of this to
This is a portion of my script for installing ADFS. Pretty straightforward, but it
I have updated this script. The dynamic dropdown portion of the script requirement has
I've been trying to customize a portion of PHP script for this. I want
What is the purpose of this bash script? (It is a portion of a
This script should detect the last portion in the full path, and if it
I have a script that creates a table like this: class TableClass < Table
Running my script through Devel::NYTProf showed that the following portion of code took up
Here is a portion of my app.yaml file: handlers: - url: /remote_api script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py
My scripts are running fine on chrome and IE but won't start on firefox

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.