Node.js Modules
Node.js Tutorial » Node.js Modules
What are node.js modules?
In Node.js, modules are blocks of encapsulated code that communicate with an external application based on their functionality.
Modules can be a collection of multiple files / folders or a single file.
The reason why programmers rely heavily on modules is because of their reusability, as well as their ability to break down a complex piece of code into easy-to-manage pieces.
Built-in Modules
Node.js has a set of built-in modules which you can use without any further installation. These modules can be loaded into the program by using the require function.
The require() function will return a JavaScript type depending on what the particular module returns.
Include Modules Example
The following example demonstrates how to use the Node.js Http module to create a web server.
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('Welcome to Nodejs page!');
}).listen(1443);
In the above example, the require() function returns an object because the Http module returns its functionality as an object.
The function http.createServer() method will be executed when someone tries to access the computer on port 1443.
Create Your Own Modules
You can create your own node.js modules and easily include them in the applications you need.
In the following example, we created a module that returns a date and time object:
return Date(); };
Save the code above in a file called "my_first_module.js"
Include Your Own Module
Now you can include and use the module in any of your Node.js files.
var dt = require('./myfirstmodule');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write("The date and time are currently: " + dt.myDateTime());
res.end();
}).listen(8080);DROP VIEW [France Customers];
node.js modules, list, example, install, can be exposed using, documentation, module exports, explained, path, tutorial, can be exported using
What are some popular node js modules?
What are node modules used for?
What are js modules?
What are the CommonJS modules?
Node.js Modules - nodejs
This tool makes it easy to create, adjust, and experiment with custom colors for the web.

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.

Find here examples of creative and unique website layouts.

Find here examples of creative and unique website CSS HTML menu.