Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript NodeJS入门-在NodeJS中找不到模块_Javascript_Node.js_Npm - Fatal编程技术网

Javascript NodeJS入门-在NodeJS中找不到模块

Javascript NodeJS入门-在NodeJS中找不到模块,javascript,node.js,npm,Javascript,Node.js,Npm,我是NodeJS新手,我正试图根据NodeJS站点上的指南在NodeJS中创建一个服务器。我已经在我的计算机上安装了NodeJS,并用下面的代码生成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.setH

我是NodeJS新手,我正试图根据NodeJS站点上的指南在NodeJS中创建一个服务器。我已经在我的计算机上安装了NodeJS,并用下面的代码生成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}/`);
});
然后,我尝试通过在cmd(Windows 10)中键入
node app.js
命令来运行代码。之后显示以下错误

C:\Users\Nuwanst\Documents\NodeJS\test2>node appjs
module.js:471
    throw err;
    ^

Error: Cannot find module 'C:\Users\Nuwanst\Documents\NodeJS\test2\appjs'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:389:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:504:3

如何修复此问题?

根据错误,我认为您在cmd中运行node.js时出现了错误。
应该是
node app.js
而不是
node appjs

您应该编写node app.js而不是node apjs