5

How can i use/call Nodejs's Buffer in Angularjs ? i spent many hours in google but i can not find the answer. Thanks for your help.

6
  • In nodeJs, i wrote some code like: var buffer = new Buffer(9); buffer.writeUInt8(3, 0); buffer.writeUInt32LE(0x00040000, 1); buffer.writeUInt32LE(10, 5); how i can do the same thing in Angulars JS ? Thanks for any reply. Commented May 26, 2017 at 15:00
  • 1
    Buffer is a native Node.js API. It does not exist in standard JS Commented May 26, 2017 at 15:02
  • @borislemke: Thanks for your reply. i found this module npmjs.com/package/buffer, can i import and use it in my Angular app ? if yes, how can i do it ? Commented May 26, 2017 at 15:17
  • possible duplicate of stackoverflow.com/questions/8880571/… Commented May 26, 2017 at 15:23
  • I'm not familiar with that module, but if it works as it describes itself, you might as well give it a try Commented May 26, 2017 at 15:32

1 Answer 1

3

I found the solution. The idea is using ArrayBuffer, DataView of Javascript to make the same thing as Buffer of NodeJS.

For example, in NodeJS, i wrote something:

var buffer = new Buffer(9); 
buffer.writeUInt8(3, 0); 
buffer.writeUInt32LE(0x00040000, 1); 

The corresponding code in Javascript like the following:

 var buffer = new ArrayBuffer(9);
 var dataview = new DataView(buffer);
 dataview.setUint8(0, 3);            
 dataview.setUint32(1, parseInt('0x00040000'), true);

Hope this helps for anyone have the same problem.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi @V-Q-A-NGUYEN , do you know how can I use this method to convert this type of buffer usage?Buffer.from('some text', 'utf8')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.