Node.js comes with dozens of built-in modules. These built-in modules, sometimes referred to as core modules, give you access to tools for working with the file system, making http requests, creating web servers, and more
The module system is built around the require function. This function is used to load in a module and get access to its contents. require is a global variable provided to all our Node.js scripts
Let’s look at an example
const fs = require(‘fs’)
fs.writeFileSync(‘notes.txt’, ‘I live in Philadelphia’)
The script above uses require to load in the fs module. This is a built-in Node.js module that provides functions you can use to manipulate the file system. The script uses writeFileSync to write a message to notes.txt
List of all core module in Node.js
Core Module | Description |
---|---|
http | http module includes classes, methods and events to create Node.js http server. |
url | url module includes methods for URL resolution and parsing. |
querystring | querystring module includes methods to deal with query string |
path | path module includes methods to deal with file paths |
fs | fs module includes classes, methods, and events to work with file I/O. |
util | util module includes utility functions useful for programmers. |