5 ms·
There’s no guarantee one is set right?
by reaktivo 3y ago
There’s no guarantee one is set right?
- throwanem 3y agoNo more so than that any other kind of config file is present and complete, I suppose.
- mordechai9000 3y agoI don't know that this is the best way, but I use a module that instantiates a proxy object. It populates the config object behind the proxy at startup and crashes with a useful message if a value is missing. If something tries to get an undefined value at runtime, the proxy also throws an error. This way the module documents the config, and the app crashes if something is missing rather than silently trying to run with an undefined value. You can also use object.freeze or what have you to make the config object immutable for most practical purposes.
- throwanem 3y agoI don't know if that's the best way either, but it's the model all the most successful engineering cultures I've been part of have used, which certainly says a lot for it in my view at least.
- samtho 3y agoThere’s also no guarantee the application will be able to reach a database, bind to a port, or read something off of a file system.
- madeofpalk 3y agoTypescript types them to be string | undefined.
- moralestapia 3y agoA type system doesn't really solve that issue tho.
- mixedCase 3y agoA "runtime type system" does, meaning something like io-ts or zod. It also allows statically typing and transforming env strings into much more useful and complex structures.
- aabbcc1241 3y agoYou can use validator like populate-env[1] to check for missing env variables [1] https://www.npmjs.com/package/populate-env https://www.npmjs.com/package/populate-env