NodeJS入门 – 在nodeJS中找不到模块

我是NodeJS的新手,我试图在NodeJS中根据NodeJS站点上的指南创build一个服务器。 我已经安装了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)中inputnode 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