You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using module-alias package with dotenv at the same time.
.env is working as expected in src/index.ts, but it's not working in other files like src/helpers/axios.ts.
I created an axios instance with api key which is loaded from .env.
I will drop the code snippets here for reference.
src/index.ts
import express, { Express, Request, Response } from 'express'
import bodyParser from 'body-parser'
import cors from 'cors'
import dotenv from 'dotenv'
import 'module-alias/register' // Register module aliases
import { router } from './routes'
console.log(process.env.API_KEY) // -------------------------------------> this is working properly
dotenv.config({ path: `${__dirname}/../.env` })
src/helpers/axios.ts
import axios from 'axios'
export const BASE_URL = 'https://test-base-url.com'
console.log('ENV - ', process.env.API_KEY) // -------------------------------------> this is not working
export const swapkitInstance = axios.create({
baseURL: EASYBIT_BASE_URL,
headers: {
'Content-Type': 'application/json',
'API-KEY': process.env.API_KEY,
},
})
I'm using
module-alias
package withdotenv
at the same time..env
is working as expected insrc/index.ts
, but it's not working in other files likesrc/helpers/axios.ts
.I created an axios instance with api key which is loaded from
.env
.I will drop the code snippets here for reference.
src/index.ts
src/helpers/axios.ts
package.json
nodemon.json
Any help would be appreciated.
The text was updated successfully, but these errors were encountered: