How do I add a custom script to my package.json file that runs a javascript file?

前端 未结 6 874
生来不讨喜
生来不讨喜 2020-11-29 17:01

I want to be able to execute the command script1 in a project directory that will run node script1.js.

script1.js is a file in

6条回答
  •  天命终不由人
    2020-11-29 17:39

    I have created the following, and it's working on my system. Please try this:

    package.json:

    {
      "name": "test app",
      "version": "1.0.0",
      "scripts": {
        "start": "node script1.js"   
      }
    }
    

    script1.js:

    console.log('testing')
    

    From your command line run the following command:

    npm start
    

    Additional use case

    My package.json file has generally the following scripts, which enable me to watch my files for typescript, sass compilations and running a server as well.

     "scripts": {
        "start": "concurrently \"sass --watch ./style/sass:./style/css\" \"npm run tsc:w\" \"npm run lite\" ",    
        "tsc": "tsc",
        "tsc:w": "tsc -w", 
        "lite": "lite-server",
        "typings": "typings",
        "postinstall": "typings install" 
      }
    

提交回复
热议问题