- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Node.js – v8.serialize() Method
The v8.serialize() method provides a method to serialize JavaScript values in a way that is compatible and therefore can be used with HTML structured clone algorithm. The format is also backward compatible. Equal or same JavaScript objects may result in different serialized outputs.
Syntax
v8.serialize(value)
Parameters
It takes a single parameter −
value − The input parameter that needs to be serialized.
The function returns a buffer output after serializing the input value.
Example 1
Create a file with the name "serialize.js" and copy the following code snippet. After creating the file, use the command "node serialize.js" to run this code.
// v8.serialize() Demo Example // Importing the v8 module const v8 = require('v8'); // Initializing the data variable var data = "Welcome to Tutorials Point !" // Printing the serialized value console.log(v8.serialize(data));
Output
C:\home
ode>> node serialize.js <Buffer ff 0d 22 1c 57 65 6c 63 6f 6d 65 20 74 6f 20 54 75 74 6f 72 69 61 6c 73 20 50 6f 69 6e 74 20 21>
Example 2
Let’s have a look at one more example
// v8.serialize() Demo Example // Importing the v8 module const v8 = require('v8'); // Initializing the data variable var data = "Welcome to Tutorials Point !" // Printing the serialized value console.log('Serializing data', v8.serialize(data)); console.log('Serializing numbers', v8.serialize(12345)) console.log('Serializing decimal value', v8.serialize(12345.543))
Output
C:\home
ode>> node serialize.js Serializing data <Buffer ff 0d 22 1c 57 65 6c 63 6f 6d 65 20 74 6f 20 54 75 74 6f 72 69 61 6c 73 20 50 6f 69 6e 74 20 21> Serializing numbers <Buffer ff 0d 49 f2 c0 01> Serializing decimal value <Buffer ff 0d 4e dd 24 06 81 c5 1c c8 40>
Advertisements
To Continue Learning Please Login
Login with Google