An very easy to user ini file parser and serializer for node.js
npm install --save ezini
const ini = require("ezini");
ini.parse(str, (obj) => {
console.log(obj)
})
or use the synchronize version parseSync(str)
ini.stringify(obj, (str) => {
console.log(str)
})
or use the synchronize version stringifySync(obj)
Giving a example ini file foobar.ini
which looks like this:
[owner]
name=John Do
organization=Acme eProducts
rich=true
richStr="true"
[database]
server=192.0.2.42
; use IP address in case network name resolution is not working
port=143
portStr="143"
file = "acme payroll.dat"
You can parse this ini file like this:
str = fs.readFileSync(".foobar"), "utf-8")
ini.parse(strINI, (obj) => {
console.log(obj)
})
and then obj
would looks like this:
{ owner:
{ name: 'John Do',
organization: 'Acme eProducts',
rich: true,
richStr: 'true' },
database:
{ server: '192.0.2.42',
port: 143,
portStr: '143',
file: 'acme payroll.dat' } }
You can also stringify the object:
ini.stringify(obj, (str) => {
console.log(str)
})
str
would looks like this:
[owner]
name=John Do
organization=Acme eProducts
rich=true
richStr="true"
[database]
server=192.0.2.42
port=143
portStr="143"
file=acme payroll.dat