dotfiles

path: courses/express-node/dotfiles.md

- **fileName**: dotfiles
- **Created on**: 2024-06-29 04:54:54

installation :

npm i dotenv

is a way to store import info ( api key , privateData) for the user or software and dont forget to ignore it from .gitignore

store the data in file with .env extension :
SECRET="yossefsabry"

using with node ( express ):

import express from 'express';
import dotenv from 'dotenv'
// for get the path for the  currnet file
import path from 'path'
import {fileURLToPath} from 'url' 

// ge the current directory name
const __dirname = path.dirname(fileURLToPath(import.meta.url)) 
// go locate the .env file in side /server/config/.env
dotenv.config({path:path.join(__dirname,'../config/.env')}); 

const app = express();
const port = process.env.PORT || 3000;

app.listen(port, () => {
	console.log(`listen in port ${port}`)
})


// now you can get any data from any where in the project for examle i want to ge the url for `process.env.URL`

continue:express-validator.md
before:redis.md