Tell us what’s happening:
Code is correct, tests are not passing. It is working as expected. Used the same syntax. Red the value from the .env
inside the route handler. dotenv
package is installed. I tried everything. Also tried npm run update --all
.
myApp.js file:
require('dotenv').config();
let express = require('express');
let app = express();
app.use('/public', express.static(__dirname + "/public"))
app.get('/json', (_, res) => {
let message = process.env.MESSAGE_STYLE === 'uppercase' ? "HELLO JSON" : "hello json";
res.send({ message: message })
});
app.get('/', (_, res) => {
res.status(200).sendFile(__dirname + "/views/index.html")
})
module.exports = app;
Link for the result ( might not work at all times as I might restart the pod now and then ):
To be mentioned that the link above is the one where you can see the JSON payload response.
I have submitted the root link ( without the /json
path ) :
Your project link(s)
solution: boilerplate-express - Replit
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36
Challenge: Basic Node and Express - Use the .env File
Link to the challenge: