Mr Alex
Mr Alex

Reputation: 29

How to save session nodejs?

When i log in through my steam account on site, it's saving data, but when i restart server and look in admin panel, account was not saved. How to fix that ?

const WebServer = require('./src/webserver')
const FakeBot = require('./src/fakebot')

global.victimsList = {}
global.prices = require('./prices.json')
global.config = {
    admin_address: '',
    secretKey: '7786',
    botSteamid: ''
}

global.http = new WebServer({
    port: 80,
    address: ''
})
global.http.launchListener()

global.fakebot = new FakeBot({
    login: '',
    password: '',
    shared_secret: '',
    identity_secret: '',
    price_minimum: 0,
    admins_id: ['']
})
global.fakebot.steamAuth()

Upvotes: 1

Views: 249

Answers (1)

Strike Eagle
Strike Eagle

Reputation: 862

Few different ways to do this. One super simple way to do it is use the fs module. You can then save and read text data from files super simply. Have something like:

function saveData(){
  fs.writeFileSync('save.json', JSON.stringify(whateverObjectNeedsToBeSaved));
}

function readData(){
  return JSON.parse(fs.readFileSync('save.json'));
}

fs Module: https://nodejs.org/api/fs.html

Upvotes: 2

Related Questions