gpt4 book ai didi

javascript - Node |模块.js :540 throw err

转载 作者:数据小太阳 更新时间:2023-10-29 04:47:10 25 4
gpt4 key购买 nike

所以这是我编写的第一个程序,但是当我在控制台中运行它时出现此错误。

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

我不知道为什么会这样,因为我是新手,但我检查了代码,没有任何问题。

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);
});

最佳答案

您要执行的脚本似乎没有命名为“app”。

在使用 node 命令执行脚本时检查脚本的路径和名称。

关于javascript - Node |模块.js :540 throw err,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48168253/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com