如何在 package.json 中运行 Node.js 项目。

huangapple go评论55阅读模式
英文:

How to run nodejs project in package.json

问题

我正在使用Nodejs工作,现在我正在尝试运行Nodejs项目(已存在),我该如何做?这是我的package.json文件:

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

我尝试使用以下代码,但不起作用,我该如何做?

npm jest
英文:

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

答案1

得分: 2

"scripts"字段中的内容已翻译如下:

"scripts": {
    "test": "jest",
    "build": "tsc",
    "lint": "eslint . --ext .ts,.js,.md -c .eslintrc.json --fix",
    "prepublishOnly": "npm run build",
    "dev": "next dev" // 注意,我在这里删除了尾随逗号
},

要运行您的命令,请执行以下操作:

启动项目:

npm run dev

运行测试:

npm run test

基本思想就是 npm run [script]

英文:

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]

答案2

得分: 1

运行项目:

npm run dev

运行单元测试:

npm run test

英文:

To run your project:

npm run dev

To run unit tests:

npm run test

答案3

得分: 0

你可以在终端中使用npm run [script]命令来运行你的脚本。在你的情况下,运行npm run test

英文:

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

答案4

得分: 0

你可以运行任何脚本。它必须在package.json文件中定义。
例如,将您的package.json定义如下:

"scripts": {
    "start": "node index.js",
    "test": "mocha test/**.spec.ts"
}

一旦定义好,您可以运行以下命令:

  • npm run start -> 启动服务器
  • npm run test -> 运行使用mocha的单元测试(仅为示例)
英文:

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)

huangapple
  • 本文由 发表于 2023年1月10日 20:36:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75070074.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定