npm启动错误但节点index.js有效

时间:2016-10-07 15:31:05

标签: json node.js npm

我开始学习nodejs并按照本教程创建一个简单的Web应用程序。

https://blog.risingstack.com/node-hero-tutorial-getting-started-with-node-js/

根据教程,我可以使用  npm start'运行网络应用程序。或节点index.js' 。当我使用节点install.js它工作并给出结果。但是当我使用npm start时会发生此错误。

npm ERR! Linux 4.4.0-38-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "start"
npm ERR! node v4.2.6
npm ERR! npm  v3.5.2
npm ERR! file /var/www/html/nodejs/package.json
npm ERR! code EJSONPARSE

npm ERR! Failed to parse json
npm ERR! Unexpected token '/' at 1:1
npm ERR! // package.json
npm ERR! ^
npm ERR! File: /var/www/html/nodejs/package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR! 
npm ERR! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file.    JSON.parse

npm ERR! Please include the following file with any support request:
npm ERR!     /var/www/html/nodejs/npm-debug.log

由于我是nodejs和npm的初学者,我无法弄清楚出了什么问题。 有谁知道如何解决这一问题 ?提前谢谢。

1 个答案:

答案 0 :(得分:2)

package.json中有错误。您无法使用评论// package.json。有关详细信息,请参阅this answer

描述您遇到的两种情况:

当您使用npm start时,您正在使用npm的CLI查看该项目目录的package.json并运行start value处存在的任何命令。如果您想使用npm start运行自己的应用,那么package.json就行了这样一行:

...
"scripts": {
  "start": "node index.js"
},
...

package.json是JSON,因此它需要像有效的JSON一样进行解析。

当你使用node index.js时,你完全绕过npm并使用node来启动index.js。如果package.json中存在解析错误,则无关紧要,因为该文件未被使用。

相关问题