node.js中的'npm start'不起作用

开发者

节点App.js有效,但是npm start不起作用。

我只是遵循了这个nodejs教程该教程由韩语编写)。

我试图将代码更改为:

“ scripts”:{“ start”:“ webpack-dev-server”},但是没有用。

这是我的代码:App.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"
}

package-lock.json

{
  "name": "codlab-nodejs",
  "version": "1.0.0",
  "lockfileVersion": 1
}

这是错误的消息。

C:\Users\김동희\codlab-nodejs>npm start

> [email protected] 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! [email protected] start: `node js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章