I have found an article about properties file reader in node js here: https://www.npmjs.com/package/properties-reader
There is a module as 'properties-reader'. But, I'm unable to understand how to define the property file. Should it be a json?
It's an ini format, as described here:
# contents of properties file
[main]
some.thing = foo
[blah]
some.thing = bar
Its not a Json format, but in ini format.
Steps to set up properties file and to read it from your node module:
make any properties file such as app.properties inside your project directory. The file may contain data like:
\#comment(ignored)
sever.port=3000
Run the following command to install properties-reader locally:
npm i properties-reader
once done use the properties-reader like this:
const PropertiesReader = require('properties-reader');
const prop = PropertiesReader('path/to/app.properties');
/*gets property from path/to/app.properties
You can also export this function using module.exports*/
getProperty = (pty) => {return prop.get(pty);}
//call the getProperty method
console.log(getProperty('server.port')); //3000
Easy as that!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With