Env test not passing

Tell us what’s happening:
I’ve been trying different ways to complete this challenge all working perfectly both locally and live environment but for some reason the test does not seem to pass.

Your project link(s)

solution: https://cb-sheldon.herokuapp.com/json

App.js

var express = require('express');

var app = express();

require('dotenv').config();

const absolutePath = __dirname + '/views/index.html';

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

app.get('/', function (req, res) {

  res.sendFile(absolutePath);

});

if (process.env.MESSAGE_STYLE === 'uppercase') {

  app.get('/json', function (req, res) {

    res.json({ message: 'HELLO JSON' });

  });

} else {

  app.get('/json', function (req, res) {

    res.json({ message: 'Hello json' });

  });

}

module.exports = app;

Your browser information:

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

Challenge: Use the .env File

Link to the challenge:

Welcome there,

Some things to take note:

  1. You should not be submitting the /json route as a solution. The tests expect your app URL, and they add the necessary routes/parameters themselves. That is, by submitting https://example.com/json, the tests will try to make a request to https://example.com/json/json
  2. You should only be defining 1 GET /json route. Currently, you have 2.

Hope this helps

I pasted the URL with the /jsonendpoint by mistake but in the challenge, I pasted it without it.

regarding the definitions, a few tries later I refactored my code to this:

app.get('/json', function (req, res) {

  if (process.env.MESSAGE_STYLE === 'uppercase') {

    response = 'Hello World'.toUpperCase();

  } else {

    response = 'Hello World';

  }

  res.json({ message: response });

});

Still the same result.

Have a double look at this and the instructions.

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