-
Notifications
You must be signed in to change notification settings - Fork 0
How to create the .env file ?
esafar edited this page Apr 27, 2023
·
7 revisions
Depending on your app, you could need more or less datas that must stay away from public github repositories. The more sensitives one are:
- API keys
- Secrets
For easier usage, it could also be interesting using env variables for urls and macros.
DATABASE_NAME="postgres"
DATABASE_PORT="5432"
POSTGRES_USER="esafar"
POSTGRES_PASSWORD="strongpassword"
POSTGRES_DB="postgresdatabase"
DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DATABASE_NAME}:${DATABASE_PORT}/${POSTGRES_DB}?schema=public"
# If you are generating JsonWeb Tokens
JWT_SECRET='mysupersecret'
FRONTEND_URL="http://localhost:3000"
BACKEND_URL="http://localhost:3333"
SOCKET_URL="http://localhost:3080"
GAME_URL="http://localhost:4343"
# This is the redirect URI found in my 42 intranet, where the app was created
# You can simply copy past it
API42_REACT_APP_URL="https://api.intra.42.fr/oauth/authorize?client_id=myclientid&redirect_uri=myredirecturi&response_type=code"
# You can simply copy past it
API42_CLIENT_ID="myclientid"
# You can simply copy past it
API42_CLIENT_SECRET="myclientsecret"
# You enters here where you want your connection with 42 account to redirect you
# Example: for me, it was to my backend request: http://localhost:3333/auth/42/callback
API42_REDIRECT_URI="where_i_want_the_callback_to_go_after_connection"
- Install the packages:
$ npm i --save @nestjs/config
- Import the module in your code
- Call the var using:
process.env.API42_CLIENT_SECRET;
- Depending on your app, it could be different. But the logic is the same to the
backend
. Let's say I am using React. The only difference would be that myenv
variables must start withREACT_APP_
in order to make react recognize them.
how to import the module in my nestjs: https://docs.nestjs.com/techniques/configuration how to use env var in react: https://create-react-app.dev/docs/adding-custom-environment-variables/
[Fill this...]