lundi 5 décembre 2016

NodeJS: How to have the same code for local / prod enviroments

I'm trying to figure out how to build my app so it doesn't have to differentiate between the enviroment.

For example I have a function called UpdateConfig() which when run on local simply reads a json from a path. The same function ran on prod reads the same json but gets it from an AWS S3.

A way to code this would be :

if( enviroment == LOCAL ) json.readFile('path', ...);
else S3.getObject(options, ...);

What approach should I take in order to have the same code for both enviroments?

Are there any general rules I should look out for in order to make sure my code doesn't need to take in consideration what enviroment I'm in?

Aucun commentaire:

Enregistrer un commentaire