Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
isomorphic-config
Advanced tools
Readme
A configuration manager for isomorphic applications
npm install --save isomorphic-config
First of all, you need to create a "config" directory in the root of your project and add a "default.json" file in it with the settings required by your app.
Just import and use it, isomorphic-config will make use of server side capabilities to read the configuration file ("/config/default.json") and retrieve the configurations in it.
const isomorphicConfig = require("isomorphic-config");
const config = isomorphicConfig.server;
const express = require("express");
let server = express();
server.listen(config.port, (err) => {
if (err) {
throw new Error(err);
} else {
console.info('Listening at http://localhost: ', config.port);
}
});
In order to use the config in a client app, you would need to expose it in a global variable ("CONFIG") from the server initial render, for later use in the app (see the "Hello" example).
const isomorphicConfig = require("isomorphic-config");
const express = require('express');
const server = express();
const hello = require("./Hello.js");
// You would be wise to only expose to the client non-sensitive configuration.
// It's a good idea to keep all client configurations in a "client" key and only expose that:
const clientConfig = {client: isomorphicConfig.client};
server.get('/', function (req, res) {
res.send(
`<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello Isomorphic Config</title>
<script charSet="UTF-8">var CONFIG=${JSON.stringify(clientConfig)}</script>
</head>
<body>
${hello}
<script>alert(CONFIG.client.greeting);</script>
</body>
</html>`
);
});
server.listen(isomorphicConfig.server.port, function () {
console.log(`Example app listening on port ${isomorphicConfig.server.port}!`);
});
const isomorphicConfig = require("isomorphic-config");
const config = isomorphicConfig.client;
const hello = `<div class="greeting">${config.greeting}</div>`
module.exports = hello;
Inspired by the config module, you can define environment variables to override specific configurations. If you're running on a server, isomorphic-config will check for the existance of a given environment variable and replace the config associated to it with it's value.
To enable custom environment variables, create a configuration file, custom-environment-variables.json (and place it in the "config") directory mapping the environment variable names into your configuration structure. For example:
{
"server": {
"port": "PORT"
},
"client": {
"greeting": "GREETING"
}
}
...would cause isomorphic-config to check for the environment variables PORT and GREETING. If they exist, they would override the values for server.port, and client.greeting in your configuration.
to centralize the way configurations are requested throughout your isomorphic application. The config module works only on server side because it uses file system to read a config file. Isomorphic Config does the same but also attemps to read the configuration from a client Global variable. Also, unlike config, it only supports json format, so code is more straight-foward and has less dependencies.
FAQs
A configuration manager for isomorphic applications
The npm package isomorphic-config receives a total of 54 weekly downloads. As such, isomorphic-config popularity was classified as not popular.
We found that isomorphic-config 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.