1

I am building a notification application in which every time an event is triggered the associated user gets a notification. I am using localstorage of NodeJs to store the information of the logged in user. The problem is that when two users are logged in,the localstorage values are overridden by the new users value.

I need to create multiple instances of NodeJS server so that every user has its own localStorage.

For example If two users log in with credentials

{
userName:name1
}

and

{
userName:name2
}

then two separate localStorage should be created one having userName:name1 and one having userName:name2.

I have tried all the solutions available online but I am unable to create multiple states of NodeJS server.

Thanks in advance

Kishan Maurya
  • 3,356
  • 8
  • 21
user10136991
  • 63
  • 1
  • 10
  • 1
    you can use redis for saving key/value pair username – Saeed Jalali Oct 20 '19 at 07:46
  • I would also suggest you to use redis, but if you are doing something more complex then you should use database, i would suggest you NoSQL DBs (firebase, mongodb, postgreSQL, etc..) – iLiA Oct 20 '19 at 08:42

2 Answers2

1

You do not have to create a new server for each user. Take the IP address and port instead. This means that each user can be uniquely identified. You can simply name the files of the users after the variable client.

Here an example code

net.createServer((netSocket : net.Socket) => {
    netSocket.on('data', (data) => {
         var client = netSocket.remoteAddress + ':' + netSocket.remotePort;
    })
})
Interface
  • 312
  • 3
  • 16
0

I wasn't able to create multiple nodejs instances hence I stored the user data in session storage and passed it to nodejs server every time I triggered a request.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user10136991
  • 63
  • 1
  • 10