Today I was wondering how we can pass arguments to an npm run target when using the node process manager PM2:

In other words, say you have the following command to run: pkg develop -p 9999, where
- develop is a script defined in your package.json, which runs pkg develop
- p represents an argument passed to the script, in this case, the port number

How do you define this command in your PM2 configuration file?

File Structure

Assume the following file structure:

- javascript
    -- package.json
    -- npm-shrinkwrap.json
- pm2
    -- config.json


    name: "my package.json",
    version: "1.0.0",
    description: "",
    main: "index.js",
    scripts: {
        develop: "pkg develop",
    author: "Don",
    dependencies: {
    devDependencies: {


The key is to use PM2’s args parameter, which accepts an array (list) of strings that comprise the command you need to run.

See for more info on all the configuration variables you can use.

Additionally, the double dash between develop and -p in the args array denotes that the arguments that come after the double dash are meant to be passed to pkg develop.

More on the double dash:

    "name": "my-pm2-process",
    "cwd": "/home/don/",
    "exec_mode": "fork",
    "env": { "NODE_ENV": "development" },
    "script": "npm",
    "args": ["run", "develop", "--", "-p", "9999"],