// Import 'http' module
const http = require('http');
// Create a simple HTTP server
const server = http.createServer((req, res) => {
res.end('Hello, Node.js!');
});
// Start the server and listen on port 3000
server.listen(3000, () => {
console.log('Server is listening on port 3000');
});Simple HTTP Server in Node.js
Continue Reading
Discover more amazing content handpicked just for you
Build a Custom Rate Limiter in Node.js with Redis
- Atomic operations with Redis
- Manual request tracking logic
- Flexibility to customize based on business rules
You’re no longer blindly relying on a package—you understand and control the system.
Building a Real-Time Chat Application with WebSockets in Node.js
npm install express socket.ioCreate a file named server.js in your project directory and add the following:
JWT Token Creation and Verification in Node.js using 'jsonwebtoken'
No preview available for this content.
Read and Write Files in Node.js using 'fs' module
No preview available for this content.
Simple RESTful API in Node.js using Express
No preview available for this content.
Date Manipulation and Sum Calculation
No preview available for this content.
Access Command-line Arguments
No preview available for this content.
Set and Access Environment Variable
No preview available for this content.
Event Emitter using 'events' module
// Import 'events' module
const EventEmitter = require('events');
// Create an EventEmitter instance
const emitter = new EventEmitter();
// Define an event listener
emitter.on('event', () => {
console.log('Event occurred');
});
// Emit the 'event' to trigger the listener
emitter.emit('event');Construct File Path using 'path' module
No preview available for this content.
Basic Authentication using 'express-basic-auth' middleware
No preview available for this content.
Create and Print Buffer
// Create a Buffer from a string
const buffer = Buffer.from('Hello, Node.js!');
// Print the Buffer as a string
console.log('Buffer:', buffer.toString());Hashing Password with SHA-256 using 'crypto' module
No preview available for this content.
Parse URL and Query Parameters
No preview available for this content.
Execute Shell Command using 'child_process' module
No preview available for this content.
File Stream Copy using 'fs' module
No preview available for this content.
Simple WebSocket Server using 'ws' library
No preview available for this content.
Discussion 0
Please sign in to join the discussion.
No comments yet. Start the discussion!