[英]Node.js package start file not working
所以我有这样的package.json文件:
{
"name": "chat_app",
"version": "0.2.0",
"description": "The second iteration of the chat app",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "index.js"
},
"author": "Tino",
"license": "MIT",
"dependencies": {
"express": "^4.14.0",
"jade": "^1.11.0"
},
"devDependencies": {
"gulp": "^3.9.1",
"gulp-jade": "^1.1.0"
}
}
这是我的index.js文件:
var app = require('express')(),
express = require('express'),
http = require('http').Server(app),
jade = require('gulp-jade');
app.use(express.static(path.join(__dirname, '/public')));
app.get('/', function(req, res) {
res.sendfile(__dirname + '/index.html');
})
http.listen(3000, function() {
console.log('listening on localhost:3000');
})
当我键入: node start
它不起作用。 为什么是这样? 非常感谢您的帮助。
谢谢
package.json中的脚本应显示为:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
要运行这些脚本,请使用以下命令
npm test
要么
npm start
使用npm脚本使您可以灵活地链接命令和使用构建工具。
例
安装nodemon,该工具可在您进行更改时自动重新启动节点应用程序。
只需使用nodemon而不是node来运行代码,现在,当代码更改时,您的进程将自动重新启动。 ...从终端运行:
npm install -g nodemon
现在在您的package.json中添加以下脚本:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js",
"dev": "nodemon index.js"
},
然后从您的命令行运行以下命令:
npm run dev
这应该使您对npm脚本的工作原理有基本的了解。
这些脚本只需运行您在shell /终端中编写的命令即可。 因此,如果要运行npm start
并让节点运行index.js
,则需要编写
"scripts": {
"start": "node index.js"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.