How to use .env file

Guys, I’m really stuck on this topic. can anybody help me?

the .env can no longer be created directly in “Files”, so I created it in the “secrets” folder. But it still doesn’t work and I have no idea what is going on!

This is my code:

var express = require('express');
var path = require('path');
var app = express();

app.get("/", function(req, res) {
  res.sendFile(__dirname+ "/views/index.html");
})

app.use("/public",express.static(__dirname + "/public"))

app.get("/json", (req, res) => {
  res.json({
    message: "Hello json"
  });
});

app.get('/json', (req, res) => {
  const mySecret = process.env['.env']
  mySecret === 'uppercase' ? 
    res.json({ "message": "HELLO JSON" }):
    res.json({ "message": "Hello json" })
})


 module.exports = app;

Having two GET handlers for the same thing can’t be right

The logic is correct here but this is not a correct was to use a ternary.

1 Like

Omg total lack of attention.
Thank you !

1 Like

Were you able to solve it? Might need some logic there.

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