Welcome to the Node.js Modules Exploration repository! This repository is dedicated to understanding and implementing the core modules in Node.js, including fs, os, http, and events. Dive in and master these essential functionalities of Node.js! π»π
This repository is your guide to mastering some of the most important modules in Node.js. Each module is covered with examples and explanations to help you understand their usage and applications in real-world scenarios.
- File System (
fs): Learn how to work with the file system to read, write, and manipulate files. - Operating System (
os): Get insights into the operating system-related information and methods. - HTTP (
http): Understand how to create HTTP servers and handle requests and responses. - Events (
events): Explore the events module to handle asynchronous events in your applications.
To get started, clone the repository and install the necessary dependencies:
git clone https://github.com/sanjaraiy/nodejs_work.git
cd nodejs_work
npm installEach module has its own directory with detailed examples and explanations. Navigate to the desired module and run the example scripts:
cd fs
node example.jsExample of reading a file:
const fs = require('fs');
fs.readFile('example.txt', 'utf8', (err, data) => {
if (err) throw err;
console.log(data);
});Example of getting OS information:
const os = require('os');
console.log('Platform:', os.platform());
console.log('CPU Architecture:', os.arch());
console.log('Total Memory:', os.totalmem());Example of creating an HTTP server:
const http = require('http');
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello, World!\n');
});
server.listen(3000, () => {
console.log('Server running at http://localhost:3000/');
});Example of using EventEmitter:
const EventEmitter = require('events');
const eventEmitter = new EventEmitter();
eventEmitter.on('start', () => {
console.log('Started!');
});
eventEmitter.emit('start');We welcome contributions! Please read our content and to get started.
Happy coding! πβ¨