Dino Geek, try to help you

How to use Buffers in Node.js?


Buffers are used in Node.js to handle binary data. They store raw data in an array format which can be converted into various other formats like JSON, String, Array, etc.

Here’s a general example of how to use Buffers in Node.js:

```
// Create a new buffer containing the word ‘Hello‘
let buffer = Buffer.from(‘Hello’);

console.log(buffer);
// Logs:

console.log(buffer.toString());
// Logs: Hello

// Create a new buffer of length 10 and add values to it.
let buffer2 = Buffer.alloc(10);
buffer20 = 2;
buffer21 = 255;

console.log(buffer20);
// Logs: 2
console.log(buffer21);
// Logs: 255
```

Buffer.from() method is used to create a new buffer with a string or an array. In the above code lines, Buffer.from(‘Hello’) creates a new buffer having the binary representation of ‘Hello’ in UTF-8 encoding.

Buffer.alloc() method is used to create a new buffer with specified length.

In Node.js applications, Buffer is mainly used to read images or audio files, or to get raw data from files.

To understand more about the methods available with Buffer class: https://nodejs.org/api/buffer.html


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use