0

I am working on a simple nodejs app by using typescript. As I am going to deploy this app in different envs I need to tell which env file to take when building the app.

npm run build (node_modules/.bin/tsc)

Is there a way to tell tsc which env file he should take when building the app? And how do I implement that in the code?

2
  • "As I am going to deploy this app in different envs I need to tell which env file to take when building the app" - if you have 5 different envs then with this approach you'll end up having 5 customised versions of your build. As a sidenode, Docker containers are meant to change that: you build the container once and then you can deploy it in different hosting environments. And it just works, be it Heroku or Google Cloud or Amazozn AWS or Azure. Commented Apr 25, 2020 at 5:18
  • @winwiz1 I really like your idea! Actually I am using Firebase and deploying an Angular app and Firebase Functions. For the Angular build I need to tell which env file it should take. As I already use this approach I want to do it the same way also for Firebase Functions. Commented Apr 25, 2020 at 14:35

1 Answer 1

1

I am not sure if you can do that through TSC.

But you can create a separate JSON file which will contain your env specific items. And when your app is built it will contain the right settings from the JSON.

Consider having this environment variable

if(process.env.DEPLOYMENT == "prod"){
  fs.writeFile("config.json", JSON.stringify({
  // your specific production settings come here
  loginEndpoint: "https://productionDomain.com/login"
}))

if(process.env.DEPLOYMENT == "local"){
 fs.writeFile("config.json", JSON.stringify({
 // your specific local configuration and so on
 loginEndpoint: "http://localhost:3000/login"
}))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.