node.js - Saving session data across multiple node instances -


i'm working on platform decided have api running on port 3001 whilst web application running on port 3000. decision made make monitoring traffic more easy.

now, we're talking express applications defaulted using express-session npm package. wondering if it's @ possible save session data stored on node instance running on port 3001 , retrieved node instance running on port 3000 if makes sense.

to elaborate, our user authentication flow:

  1. user navigates our web app running on port 3000.
  2. user signs in sends post request api running on port 3001, session data stored when credentials correct, response sent web app knows user authenticated.
  3. user refreshes page or comes web app after closing browser web app loses authenticated state. on load sends request api on port 3001 check if there's session data available, mean user logged in, can let web app know user authenticated.

(if train of thought @ fault here, please let me know)

the problem express-session doesn't seem working when doing this. i've enabled cors web app able send requests api. , express-session configuration looks like:

api.use(session({     secret: 'verysecretsecret',     resave: false,     saveuninitialized: false,     cookie: {         path: '/',         domain: 'localhost',         maxage: 1000 * 60 * 24     } })); 

preferably me solve problem without using redis, i'd know if solving problem possible using express-session , node.

preferably me solve problem without using redis

you want solve problem preferably without using right tool job.

without redis need use other database. without "something redis" (i.e. without database) need implement other way handle book example use case database.

and if you're going use database using database redis or memcached reasonable sort of things need fast access data on pretty every request. if use slower database that, application's performance suffer tremendously.

i'd know if solving problem possible using express-session , node.

yes. when use express-session redis, advised in documentation of express-session module:

if of instances work on same machine may able use database sqlite stores data in filesystem, when of instances on same box, advice still use redis simpler , more performant, , in case when need scale out easy do.

also if of session data can fit in cookie without problems, can use module:

that store of session data in cookie. (thanks robert klep pointing out in comments.)


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -