0

I'm having trouble understanding, for example, when creating a server in Node.js - where does http module come from if there is no node_modules folder in my project?

Example bellow:

const http = require('http');
const onRequest = (req, res) => {
   res.writeHead(200, {"Content-Type": "text/plain"});
   res.write('Hello World!');
   res.end();
}
const server = http.createServer(onRequest).listen(8000);

Thank you in advance.

P.S.

I don't have any other file in my project folder than this one.

Tamara Jovic
  • 209
  • 1
  • 3
  • 4

1 Answers1

1

If no node-modules then Node will search if that package is installed globally.
npm install -g packageName
If not installed globally then it will through error.
But http package ** is **built-in module in node.
So it is installed by default or you do not have to install it.

Rajan Lagah
  • 2,373
  • 1
  • 24
  • 40