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.
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.
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 #.
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.
// 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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With