user3160468
user3160468

Reputation: 75

Link to reading, editing and saving INI files in node js

I tried searching for an entire day. Either i am blind or there is no specific answer to my question. How do i do it? I'm developing a steam bot in node js and i want to load accounts - username, pass etc.. of couple of accounts from .ini file. After a long time searching i only found how to read from an .ini file using node-ini module.

      var ini = require('node-ini');

      ini.parse('./config.ini', function(err,data){
      console.log( data.Admin.pass ); //working.
      data.Admin.pass = '1136'; //not working how to change value in ini.
      data.Admin.H = 'test'; //not working as well.
      });

Upvotes: 3

Views: 8663

Answers (1)

Fernando Farias
Fernando Farias

Reputation: 196

This library (https://github.com/npm/ini) is a good option to do what you are looking to achieve.

Checkout this example from the docs:

var fs = require('fs')
  , ini = require('ini')

var config = ini.parse(fs.readFileSync('./config.ini', 'utf-8'))

config.scope = 'local'
config.database.database = 'use_another_database'
config.paths.default.tmpdir = '/tmp'
delete config.paths.default.datadir
config.paths.default.array.push('fourth value')

fs.writeFileSync('./config_modified.ini', ini.stringify(config, { section: 'section' }))

Upvotes: 9

Related Questions