I store a hash in session storage using javascript like:
window.sessionStorage.setItem('test', true);
How do I read this key using node.js?
I store a hash in session storage using javascript like:
window.sessionStorage.setItem('test', true);
How do I read this key using node.js?
You don't.
sessionStorage is a browser side API for storing values locally for the life of the browser session, that does not automatically get transmitted to the server. NodeJS is a framework and engine for creating server side applications.
Perhaps you're needing the functionality of cookies.
I have made a simple package to emulate browser's sessionStorage
.
https://www.npmjs.com/package/node-sessionstorage
You can use it like this:
const storage = require('node-sessionstorage')
storage.setItem('foo', 'bar')
console.log('item set:', storage.getItem('foo'))
I created this npm package since i'm having the same issue on my own projects,
npm i sessionstorage-for-nodejs
again this is my npm package and i created it.
const sessionStorage = require('sessionstorage-for-node');
sessionStorage.setItem('id', 'value');
console.log('product: ', sessionStorage.getItem('id'));
sessionStorage.removeItem('id', 'value');
You can use express-session
module on Node.js:
$ npm install express-session
But it can be more complicated than the way you use window.sessionStorage
, e.g. some security needs to be taken care of. For express-session
documentation, click here. For more info about how it works, click here.