javascript NodeJS | module.js:540 抛出错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48168253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NodeJS | module.js:540 throw err
提问by John Smith
So it's the first ever program I write but when I run it in the console I get this error.
所以这是我写的第一个程序,但是当我在控制台中运行它时,我收到了这个错误。
module.js:540
throw err;
^
Error: Cannot find module 'C:\Users\Daniel\Desktop\app'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
I have no idea why this is happening as I am new but I checked the code and nothing is wrong.
我不知道为什么会发生这种情况,因为我是新手,但我检查了代码,没有任何问题。
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!');
});
server.listen(port, hostname, () => {
console.log('Server started on port '+port);
});
采纳答案by NullDev
It seems like the script you wanted to execute isn't named "app".
您想要执行的脚本似乎没有命名为“app”。
Check the Path and name of your script when you execute it with the nodecommand.
使用node命令执行脚本时,请检查脚本的路径和名称。

