What are Node.js modules?
Node.js modules can be categorized into three types as core modules, user-created or local modules, and third-party modules.
- Core modules — Inbuilt modules in the node.js
- User-created modules — Modules created by the user
- Third-party modules — Shared modules created and maintained by others
Core modules in Node.js
Basically, core modules are modules that are built into node.js these modules come automatically with the node.js installation. when you creating a node project these modules are available to use without any extra installations. before using core modules we need to import those modules into our project files using require keyword and I will mention how to import, use core modules in the next section.
There are lots of core modules out there. Here, I am going to discuss a few of the most important and most used among node.js core modules.
The os module provide methods and properties related to the current operating system.
Also, there are some other methods and properties to read about all the information, you can checkout os module documentation page here.
File System module
The file system module opens the doors to interacting with the file system of your device. In this scenario, we will see how to read from a file and how to write to a file using the file system module. To read and write there are two types of methods asynchronous/non-blocking way which we will be discussed and synchronous/blocking way. If you want to look into the synchronous way and other file system functionalities, check out this documentation page.
HTTP is one of the powerful modules in the node.js world that we use in networking applications. We can create a server that listens to HTTP requests in a certain port with this functionality we can create the backend for our application. Here, I will be creating a server that listens to a given port number.
In the browser, if you type localhost:3000 as URL Node.js is awesome will be displayed as the response. Also, there is much more to HTTP than this which you can find out using node.js HTTP documentation.