JSPM

  • Created
  • Published
  • Downloads 15
  • Score
    100M100P100Q68566F
  • License MIT

'config-sets' Configure the app easily.

Package Exports

  • config-sets
  • config-sets/browser.js
  • config-sets/index.min.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (config-sets) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

config-sets: simple configure library

npm-version npm-week-downloads

Configure the app easily.

Installing

npm install config-sets

Usage example

config-sets.json //in working folder

{
  "production": {
    "isDebug": false,
    "port": 8080,
    "launch_url": "/"
  },
  "development": {
    "isDebug": true,
    "launch_url": "/options"
  }
}

app.js

var options = require('config-sets').init({
    port: 3000,
    launch_url: "/"
});

console.log('isDebug:' + options.isDebug);
console.log('profiler:' + options.profiler);

require('http').createServer(function (req, res) {

    if (req.url.startsWith('/options')) {

        res.writeHead(200, { 'Content-Type': 'text/plain' });
        res.end(JSON.stringify(options, null, 2));

        return;
    }

    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end('Hello, World!\n');

}).listen(options.port);

// Opens the URL in the default browser.
function openBrowser(url) {

    var start = (process.platform == 'darwin' ? 'open' : process.platform == 'win32' ? 'start' : 'xdg-open');
    require('child_process').exec(start + ' ' + url);
}

openBrowser(`http://localhost:${options.port}${options.launch_url}`);

select development settings

$env:NODE_ENV="development"

or

set NODE_ENV=development

select production settings

$env:NODE_ENV="production"

or

set NODE_ENV=production

License

MIT

Copyright (c) 2021 Manuel Lõhmus manuel@hauss.ee