I need a requirement on node js apis. I need to set environment in the url like http://localhost:8000/api/(env)/auth/login, where env can be dev,production.
Now I want to get that value and according to the value I need to set the database connection string (either in environment file or config file).
Requirement is----
dev environment - http://localhost:8000/api/dev/auth/login : in that case the database would be ----- test_dev and all data would be get/stored in that database -- production environment - http://localhost:8000/api/prod/auth/login : in that case the database would be test_prod and all data would be get/strored in prod database
I am confused where to write the code and how to get the environment name? I set the routes as follows ---
**in app.js file - ** app.use("/api/:environment/", apiRouter); //api router is path of api.js
**in api.js file - ** app.use("/auth/", authRouter); //authRouter is path of auth.js
**in auth.js file - ** router.post("/login", AuthController.login);
Please suggest how will I achieve this problem.
Thanks