Basic Node and Express - Use the .env File

Tell us what’s happening:
Describe your issue in detail here.

let express = require('express');
let app = express();
console.log("Hello World")


/*app.get('/',(request,response)=>{
  response.send("Hello Express")
})*/

app.get('/', (request, response) => {
  response.sendFile(__dirname + '/views/index.html')
})

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

let message = 

app.get('/json', (request, response) => {
  if (process.env['MESSAGE_STYLE'] == 'uppercase') {
    response.json({ "message": "HELLO JSON" })
  } else {
    response.json({
      "message":"Hello json "
    })
  }
})

module.exports = app;
code is working correct but it is showing
The response of the endpoint /json should change according to the environment variable MESSAGE_STYLE
what i should do to resove this
Your project link(s)

solution: https://boilerplate-express--pavan-singhsin1.repl.co

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36

Challenge: Basic Node and Express - Use the .env File

Link to the challenge:

It looks like you’ve changed your code a bit since you posted this but there are a couple of issues.

app.get('/json', (req, res) => {
  const message = process.env.MESSAGE_STYLE === 'uppercase' ? 'HELLO JSON' : 'Hello json ';
  res.json({ message });
});
  1. You have a space at the end of one of the response strings, which may be causing the tests to fail.
  2. You are now returning a json response which does not include the key ‘message’, only the value ‘HELLO JSON’ (or lowercase equivalent). It should be a key/value pair.

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