Package Exports
- config-sets
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
Configure the app easily.
Installing
npm install config-sets
Usage example
config-sets.js //in working folder
/** config-sets file */
module.exports = {
// default settings
def: {
isDebug: false,
//apiKey: process.env.API_KEY,
server: {
port: 8080,
launch_url: 'index.html'
}
},
// develop settings
dev: {
// overwriting
isDebug: true,
server: {
launch_url: 'options'
}
}
};app.js
'use strict';
var contSet = require('config-sets');
var options = contSet.assign(contSet.server, {
port: 80,
launch_url: "/"
});
var isDebug = contSet && contSet.isDebug ? true : false;
console.log('isDebug: ' + isDebug);
// 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);
}
var http = require('http');
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);
if (isDebug) {
openBrowser(`http://localhost:${options.port}/${options.launch_url}`);
} else {
openBrowser(`http://localhost:${options.port}/`);
}select develop settings
$env:NODE_ENV="dev"or
set NODE_ENV=devLicense
Copyright (c) 2021 Manuel Lõhmus manuel@hauss.ee