简体   繁体   English

如何在package.json中运行nodejs项目

[英]How to run nodejs project in package.json

I am working on Nodejs and right now i am trying to run nodejs project (existing), how can i do this?我正在使用 Nodejs,现在我正在尝试运行 nodejs 项目(现有),我该怎么做? Here is my package.json这是我的 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

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]这个想法基本上是npm run [script]

To run your project:要运行您的项目:

npm run dev

To run unit tests:要运行单元测试:

npm run test

You can run your scripts in the terminal with the npm run [script] command.您可以使用npm run [script]命令在终端中运行脚本。 In your case, run npm run test .在您的情况下,运行npm run test

You can run any scripts.您可以运行任何脚本。 It has to be defined in package.json file For example define your package.json as shown below:它必须在 package.json 文件中定义 例如定义您的 package.json 如下所示:

"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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何仅使用 index.js 和 package.json 和节点模块文件启动 nodejs 项目 - How to start a nodejs project with only index.js and package.json and node modules files 如何使用 package.json 运行 ts 脚本? - How to run ts script with package.json? 如果第二个项目的package.json不在项目的根目录中,如何在package.json中添加github依赖关系 - How to add github dependency in package.json if package.json of second project not in the root of the project 如何在 NodeJs 中更改 package.json 中的主文件 - How to change main file in package.json in NodeJs 如何在package.json文件中指定项目npm注册表 - How to specify project npm registry inside package.json file Yeoman Generator-如何解析Generator项目的Package.json - Yeoman Generator - How to Parse Package.json of Generator Project 是在Node.js中使用require与package.json相关吗 - Is the use of require related to package.json in nodejs 如何配置package.json在js和jsx文件上运行eslint - How to configure package.json to run eslint on js and jsx files 如何通过 package.json 中的脚本运行应用程序? - How to run app via script in package.json? 如何运行 TypeScript function 从 package.Z466DEEC76ECDF624FCA6D3844 脚本57DF - How to run a TypeScript function from a package.json script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM