首页 > 解决方案 > 运行 Node.js 项目的惯用方式是什么

问题描述

运行具有 package.json 和 '"main": "index.js"' 的 Node.js 项目的惯用方法是什么?我要运行“node run”或“npm run”之类的东西吗?

package.json文件:

{
"name": "bandymas",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

并且 index.js 文件存在。那么惯用的方法是什么?

标签: node.js

解决方案


您可以将start脚本添加到您的package.json

{
  "name": "bandymas",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

这样,您只需运行npm start.


推荐阅读