Skip to content

Instantly share code, notes, and snippets.

@adnanelamghari
Last active March 23, 2021 10:47
Show Gist options
  • Save adnanelamghari/e38049a0a52a6693a782453422f8cf25 to your computer and use it in GitHub Desktop.
Save adnanelamghari/e38049a0a52a6693a782453422f8cf25 to your computer and use it in GitHub Desktop.
Generate environment.ts file for angular project
const fs = require('fs');
// import { writeFile } from 'fs'; if you are using a typescript file
const environmentFile = `export const environment = {
apiUrl: ${process.env.API_URI}, // add here your variables
baseUrl: ${process.env.BASE_URI},
production: '${process.env.PRODUCTION}'
};
`;
// Generate environment.ts file
fs.writeFile('./src/environments/environment.ts', environmentFile, function (err) {
if (err) {
throw console.error(err);
} else {
console.log(`Angular environment.ts file generated`);
}
});
/*
Run npm node set-env.js (or npm ts-node set-env.ts) to generate your file
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment