Node.js Core Packages
Essential Built-in Modules
Node.js core packages are fundamental modules built into Node.js. They offer essential functionalities for various development tasks, eliminating the need for external installations. This article details some of the most commonly used core modules.
Node.js Core Packages
Introduction
Node.js core packages are built-in modules that come bundled with the Node.js runtime environment, meaning they don't require separate installation. These modules provide essential functionalities for various tasks like file system operations, networking, and more. Examples include fs (file system), http, path, os, and events.
Node.js Core Packages
fs (File System)
The fs module allows interaction with the file system, enabling operations like reading, writing, and manipulating files and directories.
const fs = require('fs');
fs.readFile('myFile.txt', 'utf8', (err, data) => {
if (err) throw err;
console.log(data);
});
Example: Reading the content of a file. This code reads the file myFile.txt asynchronously. If successful, it logs the content to the console; otherwise, it throws an error.
http
The http module enables the creation of both HTTP servers and clients, facilitating communication over the web.
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World!');
});
server.listen(3000, () => {
console.log('Server running on port 3000');
});
Example: Creating a simple HTTP server that listens on port 3000 and responds with "Hello World!"
path
The path module provides tools for working with file paths and directory structures.
const path = require('path');
const filePath = path.join('/home/user/documents', 'myFile.txt');
console.log(filePath); // Output: /home/user/documents/myFile.txt
Example: Joining path segments together safely.
os
The os module offers information about the operating system.
const os = require('os');
console.log(os.platform()); // Output: win32, linux, darwin etc.
console.log(os.arch()); //Output: x64, arm64 etc.
Example: Getting the operating system platform and architecture.
events
The events module facilitates event-driven programming.
const EventEmitter = require('events');
const emitter = new EventEmitter();
emitter.on('myEvent', (data) => {
console.log(data);
});
emitter.emit('myEvent', 'Event emitted!');
Example: Emitting and listening to custom events.
buffer
The buffer module is used for working with raw binary data.
const buf = Buffer.from('Hello');
console.log(buf.toString()); // Output: Hello
Example: Creating a buffer from a string.
crypto
The crypto module provides cryptographic functionality.
const crypto = require('crypto');
const hash = crypto.createHash('sha256');
hash.update('message');
console.log(hash.digest('hex'));
Example: Generating a SHA256 hash.
util
The util module offers various utility functions.
const util = require('util');
console.log(util.format('%s %d', 'Hello', 123)); // Output: Hello 123
Example: Using util.format for formatted output.
querystring
The querystring module is used for parsing and formatting URL query strings.
const querystring = require('querystring');
const query = querystring.stringify({name: 'John', age: 30});
console.log(query); // Output: name=John&age=30
Example: Stringifying a query object.
net
The net module enables low-level network communication using TCP sockets.
const net = require('net');
const server = net.createServer((socket) => {
socket.write('Hello from server!');
socket.end();
});
server.listen(8080);
Example: Creating a simple TCP server.
stream
The stream module provides ways to handle streaming data.
const fs = require('fs');
const readStream = fs.createReadStream('myFile.txt');
readStream.on('data', (chunk) => {
console.log(chunk.toString());
});
Example: Reading a file using a readable stream.
url
The url module offers tools for parsing and formatting URLs.
const url = require('url');
const myURL = new URL('https://example.com/path?query=string');
console.log(myURL.hostname); // Output: example.com
Example: Parsing a URL and accessing its components.
zlib
The zlib module provides compression and decompression functionality.
const zlib = require('zlib');
const data = 'This is some sample data.';
zlib.gzip(data, (err, buffer) => {
if (!err) console.log(buffer.toString('base64'));
});
Example: Zipping the data using gzip.
Summary
fs: File system operations.http: HTTP server and client creation.path: Path manipulation.os: Operating system information.events: Event-driven programming.buffer: Handling raw binary data.crypto: Cryptographic functions.util: Utility functions.querystring: Parsing and formatting URL query strings.net: Low-level network communication.stream: Stream data handling.url: URL parsing and formatting.zlib: Compression and decompression.
Discussion
Kalpesh Shewale
I am grateful to have completed my Full Stack Development with AI course at Apnaguru. The faculty's support and interactive classes helped me discover my potential and shape a positive future. Their guidance led to my successful placement, and I highly recommend this institute.
Kalpesh Shewale
I am grateful to have completed the Full Stack Development with AI course at Apnaguru. The faculty's dedicated support and hands-on approach during the classes enabled me to unlock my potential and shape a promising future. Their guidance helped me secure a placement with a good package. I highly recommend this course, and for those interested, I also suggest doing the offline version at the center for an enhanced learning experience.

Raveesh Rajput
Completing the Full Stack Development with AI course at Apnaguru was a game-changer for me. I secured an internship through this course, which gave me invaluable hands-on experience. I strongly recommend this course to anyone looking to break into the tech industry. For the best experience, I suggest attending the offline sessions at the center, where the interactive learning environment really enhances the overall experience.

swapnil shinde
Apnaguru’s Full Stack Development with AI course provided me with more than just knowledge—it opened doors to an internship that gave me real-world, hands-on experience. If you're serious about a career in tech, this course is a must. I highly recommend attending the offline sessions for the most immersive and interactive learning experience!
Kalpana Waghmare
I recently completed the Full Stack Developer with AI course on ApnaGuru, and I couldn’t be more impressed! The structure of the course, with well-organized topics and self-assessment MCQs after each section, really helped reinforce my learning. The assignments were particularly valuable, allowing me to apply what I learned in a practical way. Overall, it’s an excellent program that effectively combines full-stack development and AI concepts. Highly recommended for anyone looking to enhance their skills!
Completing the Full Stack Development with AI course at Apnaguru was a pivotal moment in my career. It not only deepened my understanding of cutting-edge technologies but also directly led to an internship that provided practical, real-world experience. If you're aiming to enter the tech field, this course is an excellent stepping stone. I especially recommend attending the in-person sessions at the center, where the dynamic, hands-on learning approach truly maximizes the benefits of the program.

Mahesh Bhosle
I completed the Full Stack Development course at Apnaguru, and it was a valuable experience. The focus on live assignments and projects gave me real-world insights, helping me apply my skills in a professional setting. The interactive live sessions, mock interviews, and question banks were excellent for job preparation. Apnaguru’s company-like environment also helped me get accustomed to real work dynamics. Overall, this course equipped me with the skills and confidence needed for a career in full-stack development. I highly recommend it to anyone seeking hands-on learning and industry relevance.
I recently completed the Full Stack course at ApnaGuru, and I’m genuinely impressed! The curriculum is well-structured, covering both front-end and back-end technologies comprehensively. The instructors are knowledgeable and provide hands-on experience through practical projects. The supportive community and resources available made learning enjoyable and engaging. Overall, it’s a great choice for anyone looking to kickstart a career in web development. Highly recommend!

Adarsh Ovhal
I recently participated in the Full Stack Development With AI Course program, and it has been incredibly beneficial. The guidance I received was tailored to my individual needs, thanks to their advanced use of AI tools. The Trainers were knowledgeable and supportive, helping me explore various educational and career paths. The resources and workshops provided were practical and insightful, making my decision-making process much clearer. Overall, I highly recommend this program to any student looking for IT Field and personalized career guidance!
Shirish Panchal
I’m currently pursuing the Full Stack Developer with AI course at ApnaGuru Training Center, and I'm impressed with what I've experienced so far. The curriculum is well-structured, covering key concepts in both front-end and back-end development, along with AI fundamentals. The instructors are knowledgeable and supportive, which makes it easy to engage and ask questions. I particularly appreciate the hands-on projects that help reinforce what I’m learning. While I’m still in the process of completing the course, I feel that I'm building a strong foundation for my future in tech. I would recommend ApnaGuru to anyone looking to explore full stack development with AI!
Apnaguru Training Center stands out as a top-notch institute for IT education. They provide a wide array of courses, including Full Stack Development, Java Full Stack, Python, Automation Testing, DevOps, and MERN/MEAN Stack, all designed to meet the demands of the modern tech industry.

Mahesh Bhosle
Apnaguru Training Center is a fantastic place for IT education! They offer a variety of courses, including Full Stack Development, Java Full Stack, and Python, all taught by knowledgeable instructors who are committed to student success. The curriculum is up-to-date and includes hands-on projects that enhance learning.
dandewar srikanth
I had an excellent experience with the full-stack web development program at APNAGURU. The instructor had in-depth knowledge of both frontend and backend technologies, which made the concepts easy to grasp. From working on HTML, CSS, JavaScript, and React for the frontend to Node.js and MongoDB for the backend, the learning curve was very smooth.