What is node-persist

Viewed 5163

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?

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.

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".

Related