'Using command line arguments in npm run script

I am trying to change the {variable} part in my custom-defined npm run deploy script

"scripts":{
      "deploy": "npm run build && scp -r ./public [email protected]:/home/{DIRECTORY}/index.js",
}

I want to run it like npm run deploy --DIRECTORY:project99



Solution 1:[1]

You can pass arguments to npm run as Environment variable. See Npm Docs

 "scripts": {
    "deploy": "npm run build && scp -r ./public [email protected]:/home/${NPM_CONFIG_DIRECTORY}/index.js"
    },

This should work

npm run deploy --DIRECTORY=project99

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 andychukse