
Security News
Open VSX Begins Implementing Pre-Publish Security Checks After Repeated Supply Chain Incidents
Following multiple malicious extension incidents, Open VSX outlines new safeguards designed to catch risky uploads earlier.
fnoc is conf backwards. This module automatically loads JSON configuration files. It first finds your package.json file and considers that the root directory of the package, the packageDir. This enables you to have multiple modules that also use fnoc. It then looks for any JSON files in the packageDir and #{packageDir}/config.
Because loading JSON writing logic to read JSON configuration files over and over is annoying. Also, I wanted a module that could load JSON config files relative to the module path and not the current directory.
npm install fnoc
Let's assume that you have a database configuration file named database.json in your ./config directory and it looks like this:
{
"host": "localhost",
"port": 27017
}
Require the fnoc function:
var fnoc = require('fnoc');
fnoc(function(err, configs) {
console.log(configs.database.host); //localhost
console.log(configs.database.port); //27017
//automatically loads package.json
console.log(configs.package.name); //YOUR PACKAGE NAME
})
It will not load nor crash if a JSON file can't be parsed. Instead, the err variable in the callback is null if no errors exist or it's an object with the file name as key and the Error object as the value.
So, let's say you have the file: /tmp/malformed.json
malformed.json:
{
this is NOT valid JSON
}
Load malformed.json:
var fnoc = require('fnoc');
fnoc(function(err, configs) {
console.log(err['/tmp/malformed.json']) //string representation of the error
})
Now Let's assume that your database configuration file looks like this:
{
"development": {
"name": "myapp_development",
"host": "127.0.0.1",
"port": 27017
},
"test": {
"name": "myapp_test",
"host": "127.0.0.1",
"port": 27017
},
"production": {
"name": "myapp_production",
"host": "myserver.com",
"port": 27017
}
}
Now if you call the env() method:
var fnoc = require('fnoc');
fnoc(function(err, configs) {
var envConfigs = configs.env();
console.log(envConfigs.database.name); //output depending upon NODE_ENV
});
Test Environment:
NODE_ENV=test node myapp.js
yields...
console.log(configs.database.name); //myapp_test
This module was written by JP Richardson. You should follow him on Twitter @jprichardson. Also read his coding blog Procbits. If you write software with others, you should checkout Gitpilot to make collaboration with Git simple.
Licensed under MIT. See LICENSE for more details.
Copyright (c) 2012 JP Richardson
FAQs
A a simple module to load config files.
We found that fnoc demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Following multiple malicious extension incidents, Open VSX outlines new safeguards designed to catch risky uploads earlier.

Research
/Security News
Threat actors compromised four oorzc Open VSX extensions with more than 22,000 downloads, pushing malicious versions that install a staged loader, evade Russian-locale systems, pull C2 from Solana memos, and steal macOS credentials and wallets.

Security News
Lodash 4.17.23 marks a security reset, with maintainers rebuilding governance and infrastructure to support long-term, sustainable maintenance.