Home > Net >  How to run nodejs project in package.json
How to run nodejs project in package.json

Time:01-10

I am working on Nodejs and right now i am trying to run nodejs project (existing) , how can i do this ? Here is my package.json

"scripts": {
    "test": "jest",
    "build": "tsc",
    "lint": "eslint . --ext .ts,.js,.md -c .eslintrc.json --fix",
    "prepublishOnly": "npm run build",
    "dev": "next dev",
  },

I tried with following code but not working,How can i do this ?

npm jest

CodePudding user response:

To run your project:

npm run dev

To run unit tests:

npm run test

CodePudding user response:

First clean this up

"scripts": {
    "test": "jest",
    "build": "tsc",
    "lint": "eslint . --ext .ts,.js,.md -c .eslintrc.json --fix",
    "prepublishOnly": "npm run build",
    "dev": "next dev" // notice i removed the trailing comma here
  },

Once that is set, run your commands

To start your project

npm run dev

To run your tests

npm run test

The idea is basically npm run [script]

CodePudding user response:

You can run your scripts in the terminal with the npm run [script] command. In your case, run npm run test.

CodePudding user response:

You can run any scripts. It has to be defined in package.json file For example define your package.json as shown below:

"scripts" :{
     "start": "node index.js",
      "test" : "mocha test/**.spec.ts"
}
Once it's defined you can run
npm run start -> to start up your server
npm run test -> to run unit test using mocha(just an example)
  • Related