4

I'm new to NodeJS and im trying to create a server in NodeJS accouding to the Guide on the NodeJS site. I already installed NodeJS to my computer and make app.js file with following code.

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

then I tried to run the code by typing node app.js command in the cmd(Windows 10). After that it shows following error.

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

how to fix this?

0

2 Answers 2

3

According to the error, I think you have got a typo when running your node.js in the cmd. It should be node app.js and not node appjs

Sign up to request clarification or add additional context in comments.

Comments

0

You should be writing node app.js instead of node apjs

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.