Node.js Modules for Beginners | How to use Node.JS Modules | What is a Module in Node.js

Опубликовано: 31 Октябрь 2024
на канале: Ali Aslan
257
16

What is a Module in Node.js?
Consider modules to be the same as JavaScript libraries.

A set of functions you want to include in your application.

Built-in Modules
Node.js has a set of built-in modules which you can use without any further installation.

Include Modules
To include a module, use the require() function with the name of the module:

var http = require('http');
Now your application has access to the HTTP module, and is able to create a server:

http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('Hello World!');
}).listen(8080);