javascript - NodeJS | module.js:540 throw err - Stack Overflow

So it's the first ever program I write but when I run it in the console I get this error.module.js

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

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);
});
Share Improve this question asked Jan 9, 2018 at 12:28 John SmithJohn Smith 731 gold badge1 silver badge3 bronze badges 7
  • Where is this project located and what mand did you use to run the application? – TGW Commented Jan 9, 2018 at 12:32
  • It seems like the script you wanted to execute isn't named "app". What mand did you use and whats the name of your file? – NullDev Commented Jan 9, 2018 at 12:33
  • Omg, How could I miss that. – John Smith Commented Jan 9, 2018 at 12:35
  • 1 You can't mark it as solved without an answer. But if the name was indeed the reason I can post it as an answer – NullDev Commented Jan 9, 2018 at 12:37
  • 1 Does this answer your question? internal/modules/cjs/loader.js:582 throw err – Henke - Нава́льный П с м Commented Jul 6, 2020 at 10:16
 |  Show 2 more ments

1 Answer 1

Reset to default 3

It seems like the script you wanted to execute isn't named "app".

Check the Path and name of your script when you execute it with the node mand.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742348249a4426985.html

相关推荐

  • javascript - NodeJS | module.js:540 throw err - Stack Overflow

    So it's the first ever program I write but when I run it in the console I get this error.module.js

    7小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信