NPM(Node Package Manager) is a package manager of Node.js packages. There is an NPM package called arraybuffer-to-string used to decode array buffers in actual strings. The package not only converts the buffer to ‘utf8’ string but also it converts the buffer to many forms like base64 encoded string, a hex-encoded string that we use in many contexts .
Command to install:
npm install arraybuffer-to-string
Syntax to import the package in local file
const arrayBufferToString = require('arraybuffer-to-string')
Syntax to convert arraybuffer to string
Parameters: It takes two parameter ‘buffer’ and ‘encodingType’ to which we want to convert the arraybuffer as shown below:
- buffer: It is the array buffer that we want to convert to the actual text. There are many methods in node.js that directly not returns the actual content of the string but return the buffer form of the response. In those contexts we use this package to convert the buffer to a string.
- encodingType: It is the optional parameter, defaualt value is ‘utf8’. it signifies the type of the string to which we want to convert the buffer. Available encoding are utf8, binary, base64, hex, ascii, latin1, ucs2, utf16 and many others.
Example 1: This example illustrates how to use ‘arraybuffer-to string’ to convert from array buffer to utf8 string.
Filename – index.js: This file contains logic to convert arraybuffer to utf8 string.
filename-form.js: This file contain logic to render the form.
Example 2: This example illustrates how to use ‘arraybuffer-to string’ to convert from array buffer to base64 encoded string.
Filename – index.js: This file contains logic to convert arraybuffer to base64 encoded string.
filename-form.js : This file contain logic to render the form.
Note: We have used some Bulma classes in form.js file to design the content.
- Node.js NPM string-to-arraybuffer Module
- Node.js NPM shortid Module
- Nodejs | Automatic restart NodeJs server with nodemon
- Node.js | NPM (Node Package Manager)
- How to install the previous version of node.js and npm ?
- What are the differences between npm and npx ?
- Steps to Create and Publish NPM packages
- How to use External Modules and NPM in a project ?
- Difference between npm and yarn
- ReactJS | Basics of ES, Babel and npm
- How to import SASS through npm ?
- How to update NPM ?
- How to import LESS through npm ?
- Introduction to NPM scripts
- What is the meaning of --save for NPM install ?
- How to update Node.js and NPM to next version ?
- Node.js NPM uuid
- How to install modules without npm in node.js ?
- Nodejs - Connect MongoDB with Node app using MongooseJS
- Cowsay in Nodejs using Requests library
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.