Last active
March 23, 2021 10:47
-
-
Save adnanelamghari/e38049a0a52a6693a782453422f8cf25 to your computer and use it in GitHub Desktop.
Generate environment.ts file for angular project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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