簡體   English   中英

NodeJS | module.js:540 throw err

[英]NodeJS | module.js:540 throw err

所以這是我寫的第一個程序,但是當我在控制台中運行它時,我得到了這個錯誤。

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命令執行腳本時,請檢查腳本的路徑和名稱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM