Can't read .env

I know this is beginner question but I need help with it. I am trying to make a username and code system. Here is the code of that part:

var Id = req.param(“id”);
var authkey = req.param(“auth_key”);
function getauth() {
try {
var filekey = process.codes.evn.parseInt(id)
if (parseInt(authkey) === filekey) {
res.json(“logged in”)
}else {
res.json(“Wrong auth_key”)
}


  } catch {
    res.json ("Invalid id")

.env file:
1=“1”

So what it does is looks for the variable called 1(for testing) and then checks of auth_key is the same as the value of the variable 1.
I know I did not close it ect… It is because I don’t want to show all the code. The issue is it says invalid id and I think it is because it’s looking for “parseInt(id)” in the .env It may not be the issue but I still am confused and need help.

Thank you and have a good day.

To read .env files, do process.env.ID in your case.
Glitch uses dotenv for .env parsing.

@Oliver_McLoughlin I am so confused. Can you post how that part of my code should look? Again I think the issue is it is looking for “parseInt(id)” instead of the variable id. Again I am a beginner.

I believe the ENV is called using process.env

Going by your code, it looks like you will have more questions beyond just the .env file.

I recommend checking out some youtube videos on setting up authentication. Brad Traversy / Traversy Media, Colt Steele, Academind, and Dave Gray Teaches Code are a few good content creators that focus on teaching web development.

It’s worth going through at least one tutorial, instead of asking questions piecemeal in a forum. You’ll definitely get this up and running faster.

1 Like

var filekey = process.env.id
replace the previous line with that

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.