0

Well I started to learn how to create api rest and when I want to call it in the proccess.env it doesn't recognize it.

I already have dotenv installed this is how my .env file looks like

this is the error, I have tried with other ports but I get the same error .

my package.json

I also tried following:

require('dotenv').config({path: '../.env'});

require('dotenv').config({path: '../../.env'});

and all I get is this

enter image description here

I hope I made myself understood, I tried to search on yt but found no answer. Thank you for your time

1 Answers1

2

You do not need to write it like that, you can just use it like this

import * as dotenv from 'dotenv'
dotenv.config()

this is possible because the default path is your root folder. Also, you are supposed to put it in your root folder as it is stated by the creators, you can read it here.

However if you really want to use it in another directory, you can read through solution on this question.