DeveloperBreeze

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());

Continue Reading

Discover more amazing content handpicked just for you

Tutorial

Build a Custom Rate Limiter in Node.js with Redis

curl http://localhost:3000

After 100 requests within an hour, you’ll get:

Apr 04, 2025
Read More
Tutorial
javascript css +1

Building a Real-Time Chat Application with WebSockets in Node.js

node server.js

http://localhost:3000/

Aug 03, 2024
Read More
Code
php

JWT Token Creation and Verification in Node.js using 'jsonwebtoken'

// Import 'jsonwebtoken' module
const jwt = require('jsonwebtoken');

// Secret key for signing and verifying JWT tokens
const secret = 'mysecretkey';

// Create a JWT token with a payload and set expiration to 1 hour
const payload = { user_id: 123, username: 'john_doe' };
const token = jwt.sign(payload, secret, { expiresIn: '1h' });

// Verify a JWT token
try {
    const decoded = jwt.verify(token, secret);
    console.log(decoded);
} catch (error) {
    console.error('Token verification failed.');
}

Jan 26, 2024
Read More
Code
javascript

Simple HTTP Server in Node.js

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Read and Write Files in Node.js using 'fs' module

// Import 'fs' module
const fs = require('fs');

// Read a file
fs.readFile('file.txt', 'utf8', (err, data) => {
  if (err) throw err;
  console.log(data);
});

// Write to a file
fs.writeFile('newfile.txt', 'Hello, Node.js!', (err) => {
  if (err) throw err;
  console.log('File written successfully.');
});

Jan 26, 2024
Read More
Code
javascript

Simple RESTful API in Node.js using Express

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Date Manipulation and Sum Calculation

// Import required modules
const moment = require('moment');
const _ = require('lodash');

// Get the current date and time using Moment.js
const now = moment();

// Example array of numbers
const numbers = [1, 2, 3, 4, 5];

// Calculate the sum of the array using Lodash
const sum = _.sum(numbers);

Jan 26, 2024
Read More
Code
javascript

Access Command-line Arguments

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Set and Access Environment Variable

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Event Emitter using 'events' module

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Construct File Path using 'path' module

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Basic Authentication using 'express-basic-auth' middleware

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Hashing Password with SHA-256 using 'crypto' module

// Import 'crypto' module
const crypto = require('crypto');

// Example password
const password = 'mypassword';

// Create SHA-256 hash of the password
const hash = crypto.createHash('sha256').update(password).digest('hex');

// Log the generated hash
console.log('Hash:', hash);

Jan 26, 2024
Read More
Code
javascript

Parse URL and Query Parameters

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Execute Shell Command using 'child_process' module

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

File Stream Copy using 'fs' module

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Simple WebSocket Server using 'ws' library

// Import 'ws' module
const WebSocket = require('ws');

// Create WebSocket Server on port 8080
const wss = new WebSocket.Server({ port: 8080 });

// Event listener for new connections
wss.on('connection', (ws) => {
  // Event listener for incoming messages
  ws.on('message', (message) => {
    console.log('Received:', message);
    // Send a response back to the client
    ws.send('Server: ' + message);
  });
});

Jan 26, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!