Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Something like Typesafe Config for NodeJS

I have a nodejs application that will take a JSON configuration file.

The JSON file will have some ${} and #{} tags that will be used to build up a dynamic context by loading a template configuration and populating the tags. HOCON may also end up being used eventually but that's not in there yet.

I came across Typesafe Config in the past and it looks amazing for this kind of thing. I did a bit of searching around npm and didn't spot anything similar in the node world but perhaps I am too unfamiliar with what terms to search for.

Does anyone know of a similar library in nodejs or a sensible strategy I may employ to do this in nodejs?

I know it wouldn't be much effort to implement something myself with string replace on the JSON or some such although I can't help but think that this has been done before in node applications and probably in a much better way than I would do it for this single use case. On that basis it seems to make sense to ask here before I continue.

like image 542
Ruairi O'Brien Avatar asked Jan 26 '15 09:01

Ruairi O'Brien


People also ask

What are the features of Typesafe configuration files?

Some features include reading config values as lists, configuration resolution, fallback configs, memory helpers, duration helpers and boolean helpers. We will be using the following two configuration files defaults.conf and overrides.conf. Loading a Typesafe Config from a resource on the classpath is a simple one liner.

How to use typesafe config with Maven?

If you want to use Typesafe Config in Java project via Maven, you can do: libraryDependencies += "com.typesafe" % "config" % "1.4.1" Here are some examples of the basic usage of Typesafe Config. It supports types such as integer, long, boolean, double, string, list and object. There are two ways to write comments: using either // or #.

What is immutable config in typescript?

Immutable. com.typesafe.config.Config is immutable, whenever you want to change something, it creates a new instance for you. It means it is safe to use even in a multi-threaded situation. You can use ConfigFactory#load () to loads the available configuration.

Is there a list of config options in a config object?

// Any path in the configuration can be treated as a separate Config object. A quick example of for a list of config options would be a configurable whitelist/blacklist. This one is a little questionable.


Video Answer


1 Answers

A bit late, but it seems there is still no dedicated npm module to convert hocon to js. However there is a library which could be easily converted to a npm module : https://github.com/scottburch/webpack-hocon-loader

like image 102
Nicolas Forney Avatar answered Oct 22 '22 17:10

Nicolas Forney