Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is node-persist

Tags:

node.js

npm

While watching online lectures of Node.js on Udemy, I came across the term node-persist.

I googled the term but didn't find any satisfactory explanation.

Kindly someone explain what node-persist is by definition?

like image 423
Syed Shahrukh Ali Gellani Avatar asked Oct 24 '25 16:10

Syed Shahrukh Ali Gellani


2 Answers

node-persist is an npm package that you can easily use in your project by executing the command:

$ npm install node-persist

node-persist is a super-easy asynchronous persistent data structures in Node.js, modeled after HTML5 localStorage

Node-persist doesn't use a database. Instead, JSON documents are stored in the file system for persistence. Because there is no network overhead, node-persist is just about as fast as a database can get.

Node-persist uses the HTML5 localStorage API, so it's easy to learn.

How to use :

const storage = require('node-persist');

//you must first call storage.init
await storage.init( /* options ... */ );
await storage.setItem('name','yourname')
console.log(await storage.getItem('name')); // yourname

If you wish to learn more about node-persist visit this site.

like image 144
handlerFive Avatar answered Oct 26 '25 09:10

handlerFive


There is no built-in module/library in Node.js that is called node-persist, however there is a 3rd party NPM module called node-persist. That module aims to provide very simple persistent storage using the file system and refers to itself as "LocalStorage for the Server".

like image 42
hackerrdave Avatar answered Oct 26 '25 11:10

hackerrdave



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!