Tuesday, 6 June 2017

Is it possible to get what package.json script has been called in NodeJS code?

Is it possible to get what package.json script has been called in NodeJS code?

My package.json file contains a script that builds the application:

{
    "name": "notes-app",
    "version": "0.0.1",
    "license": "MIT",
    "scripts": {
        "ng": "ng",
        "start": "ng serve",
        "build": "ng build && node server.js"
    },
    etc, etc...

Can I then write in my server.js file an if statement like:

if (script === 'build') {
  // Do something
}

Is there a way of knowing what script was called when starting the app. I would start this using the command npm run build. Also I'm using windows if that would make any difference.



via Garth

No comments:

Post a Comment