Search code examples
javascriptjsonnode.jsbrowserify

Run Node.js command from package.json


Can i run this command node.js from package.json ?

"browserify file.js -o bundle.js" 

if i can how i can do this and how to execute it without using command prompt?


Solution

  • npm gives you the ability to run aliased commands that you can store in your package.json file. Two basics are npm test and npm start, which respectively test and start your application (if you provide the commands that would do those things).

    You can put your aliased commands in a nested object w/in the scripts property. To run commands that aren't either start or test, you have to use npm run <command alias>. So, you could do npm run bundle.

    "scripts": {
       "test": "some test command",
       "start": "some start command",
       "bundle": "browserify file.js -o bundle.js"
    }
    

    Also, to clarify, you can't execute code from/in a JSON file, JSON is just a data interchange format.

    Hope that helps!