// Create a Buffer from a string
const buffer = Buffer.from('Hello, Node.js!');
// Print the Buffer as a string
console.log('Buffer:', buffer.toString());Create and Print Buffer
javascript
Related Posts
More content you might like
Tutorial
Build a Custom Rate Limiter in Node.js with Redis
This isn’t just a quick fix—it’s a deep dive into:
- Atomic operations with Redis
- Manual request tracking logic
- Flexibility to customize based on business rules
Apr 04, 2025
Read More Tutorial
javascript css +1
Building a Real-Time Chat Application with WebSockets in Node.js
const express = require('express');
const http = require('http');
const socketIo = require('socket.io');
const app = express();
const server = http.createServer(app);
const io = socketIo(server);
app.use(express.static('public'));
io.on('connection', (socket) => {
console.log('A user connected');
socket.on('chatMessage', (msg) => {
io.emit('chatMessage', msg);
});
socket.on('disconnect', () => {
console.log('User disconnected');
});
});
const PORT = process.env.PORT || 3000;
server.listen(PORT, () => console.log(`Server running on port ${PORT}`));<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Real-Time Chat</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="chat-container">
<ul id="messages"></ul>
<form id="chat-form">
<input id="message" autocomplete="off" placeholder="Type a message" />
<button type="submit">Send</button>
</form>
</div>
<script src="/socket.io/socket.io.js"></script>
<script src="main.js"></script>
</body>
</html>Aug 03, 2024
Read More Code
php
JWT Token Creation and Verification in Node.js using 'jsonwebtoken'
No preview available for this content.
Jan 26, 2024
Read More Code
javascript
Simple HTTP Server in Node.js
No preview available for this content.
Jan 26, 2024
Read MoreDiscussion 0
Please sign in to join the discussion.
No comments yet. Be the first to share your thoughts!