.Env file validator is a killer, no way past him/her

Tell us what’s happening:
Describe your issue in detail here.
Even though my node app works according to the requirements, the JSON output depends on the secret variable in replit (equivalent to .env variable). Still the validator says " The response of the endpoint /json should change according to the environment variable MESSAGE_STYLE" It’s impossible to get past this #Validator.

Your code so far
let express = require(‘express’);
let app = express();

app.get("/json", (req, res) => {
if (process.env.MESSAGE_STYLE === “uppercase”) {
res.json({
message: “Hello json”.toUpperCase()
});
} else {
res.json({
message: “Hello json”
});
}

});

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36

Challenge: Use the .env File

Link to the challenge:

Could you link to your code on replit?

https://boilerplate-express.adamneumann.repl.co/

let express = require(‘express’);
let app = express();

app.get("/json", (req, res) => {
if (process.env.MESSAGE_STYLE === “uppercase”) {
res.json({
message: “Hello json”.toUpperCase()
});
} else {
res.json({
message: “Hello json”
});
}

});

boilerplate-express - Replit

" boilerplate-express - Replit "

Are you sure it’s the correct link? If I visit /json route on it, there isn’t any json returned.

I had the wrong link. But now I can’t even get my code to execute. I copied from the forum. I think maybe there is a character set error.

I gives error even if i remove the code.
fcc-learn-node-with-express@0.1.0 start /home/runner/boilerplate-express

node server.js

/home/runner/boilerplate-express/myApp.js:1
let express = require(‘express’);

SyntaxError: Invalid or unexpected token
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object. (/home/runner/boilerplate-express/server.js:7:13)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1027:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! fcc-learn-node-with-express@0.1.0 start: node server.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the fcc-learn-node-with-express@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2022-05-27T19_11_58_338Z-debug.log
exit status 1

Okey here it is: https://boilerplate-express-1.adamneumann.repl.co/json

Here is the proj link: boilerplate-express-1 - Replit

Now it works. Some strange workarounds i had to make. It did not compile… gave strange errors of unexpected characters etc. Created a new proj. thx

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