node App.js 可以工作,但 npm start 不起作用。
我刚刚关注了this nodejs tutorial (教程是韩国人写的)。
我尝试将代码更改为:
“脚本”:{ “开始”:“webpack-dev-server” } 但没有成功。
这是我的代码: 应用程序.js
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
package.json
{
"name": "codlab-nodejs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node js"
},
"author": "",
"license": "ISC"
}
包锁.json
{
"name": "codlab-nodejs",
"version": "1.0.0",
"lockfileVersion": 1
}
这是错误消息。
C:\Users\김동희\codlab-nodejs>npm start
> codlab-nodejs@1.0.0 start C:\Users\김동희\codlab-nodejs
> node js
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'C:\Users\김동희\codlab-nodejs\js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! codlab-nodejs@1.0.0 start: `node js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the codlab-nodejs@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\김동희\AppData\Roaming\npm-cache\_logs\2019-08-03T14_03_42_211Z-debug.log
最佳答案
在 package.json 中更改属性“start”的值。
替换:
"start": "node js"
与:
"start": "node App.js"
关于node.js - Node.js 中的“npm start”不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57339107/