New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fileconfig

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fileconfig

json, yml file configuration loader

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
20
increased by566.67%
Maintainers
1
Weekly downloads
 
Created
Source

fileconfig

NPM

Travis Build Status

Exprimenting with configuration file loading

Install it

npm install fileconfig -g
echo "export NODE_FILECONFIG_DIR=$myconfigpath" >> ~/.profile
source ~/.profile

Use it

binaries

fileconfig

fires up a directory listing of NODE_FILECONFIG_DIR directory

JS library

assuming you have a configuration folder as follow :

+ /path/to/config/folder
  + servers
    + share
      default.yml > links to rnd/alpha.yml  
      + rnd
        alpha.yml
      + qa
        beta.yml
  • servers/share/rnd/alpha.yml
name: "Share Alpha Server"
port: 9090
dir: "/opt/share/rnd/alpha/"

Then you can fetch data as follow :

var FileConfig  = require('fileconfig');

// if env variable NODE_FILECONFIG_DIR is set
// var config = FileConfig.global();

var config  = new FileConfig("/path/to/config/folder");

var defaultServer = config.servers.share.default;
console.log(defaultServer.name);

// if at some point name property was edited in servers/share/default.yml
// or edited at runtime as follow
defaultServer.port = 8080;
// refresh from file using # prefix
defaultServer = config.servers.share['#default'];

// you can persist/store config objects to file
defaultServer.name = "Share Aplha Server R&D";
defaultServer.$persist();

Example use case

a command line program to serve a directory listing, the directories are configured

  • ~/bin/nodeHarmony
#! /usr/bin/env bash
node --harmony $@

fileconfig relies on node harmony features, hence it requires script to be run with harmony flag on

  • ~/bin/serve
#! /usr/bin/env nodeHarmony

var config      = require('fileconfig').global();
var program     = require('commander');
var express     = require('express');
var serveIndex  = require('serve-index');

program
  .command('share')
  .option('-c, --client', 'select share client', 'default')
  .action(function () {
    var serverConfig = config.servers.share[program.client];
    var share = express();
    share.use(serveIndex(serverConfig.dir, { icons : true, view : 'details' }));    
    var server = share.listen(serverConfig.port, 
      function () {
        console.log(serverConfig.name + ' is running on port ' + server.address().port);
      });
    });

program.parse(process.argv);

Now I can run the following commands

# default
serve share
# specify client
serve share -c qa/beta

Keywords

FAQs

Package last updated on 11 Apr 2015

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc