admin管理员组文章数量:1426959
I build a Node.js tool in order to change GCP config quickly. But I'm a bit stuck on the parsing of the config_nameOfConfig
file.
It looks like this :
[core]
account = [email protected]
project = project-example
disable_usage_reporting = False
[pute]
region = europe-west1-b
(This file is available in '/Users/nameOfUser/.config/gcloud'
)
And I want to convert it in an object like this :
const config = {
account:"[email protected]",
project:"project-example",
disable_usage_reporting:false,
region:"europe-west1-b",
};
I get the content of this file with the fs.readFileSync
function who converts it into a string.
An idea ?
I build a Node.js tool in order to change GCP config quickly. But I'm a bit stuck on the parsing of the config_nameOfConfig
file.
It looks like this :
[core]
account = [email protected]
project = project-example
disable_usage_reporting = False
[pute]
region = europe-west1-b
(This file is available in '/Users/nameOfUser/.config/gcloud'
)
And I want to convert it in an object like this :
const config = {
account:"[email protected]",
project:"project-example",
disable_usage_reporting:false,
region:"europe-west1-b",
};
I get the content of this file with the fs.readFileSync
function who converts it into a string.
An idea ?
Share Improve this question edited Oct 28, 2020 at 9:35 Thibault Walterspieler asked Sep 20, 2020 at 9:50 Thibault WalterspielerThibault Walterspieler 2,4222 gold badges17 silver badges27 bronze badges1 Answer
Reset to default 6This seems to be an ini file format. Unless you want to do the parsing yourself, you'd better just download a library to your project, for example:
npm install ini
Then in the code:
var ini = require('ini')
var fs = require('fs')
var config = ini.parse(fs.readFileSync('./config_nameOfConfig', 'utf-8'))
In config
you should now have object containing the data in the file.
You can console.log(config)
to see how it exactly looks like.
本文标签: javascriptParse INI file in NodejsStack Overflow
版权声明:本文标题:javascript - Parse INI file in Node.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745420278a2657869.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论