Tell us what’s happening:
Despite the message being displayed correctly in the console (all letters uppercase) when I share the link to submit the challenge it says the test is not completed. I am accessing the var from .env and the message is changed to uppercase as expected. I run out of options about what to check. Thank you
###Your project link(s)
solution: https://node-console-cr6n.onrender.com
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Challenge Information:
Basic Node and Express - Use the .env File
what does your code look like?
Hello, thank you for replying, here is the file myApp.js, the message is displayed uppercase:
app.get('/json', function(req, res) {
console.log("MESSAGE_STYLE:", process.env.MESSAGE_STYLE);
let message = "Hello json";
if (process.env.MESSAGE_STYLE === 'uppercase') {
message = message.toUpperCase();
}
res.json({ message: message });
});
is this the entire file?
I believe the first 2 lines should have been:
let express = require('express');
let app = express();
Please share the complete code in app.js.
It doesn’t hurt to also share the env file contents as well.
also if you’re using a gitpod environment, the first line in the file should be:
require(‘dotenv’).config()
damianodionori:
app.get(‘/json’, function(req, res) {
console.log(“MESSAGE_STYLE:”, process.env.MESSAGE_STYLE);
let message = “Hello json”;
if (process.env.MESSAGE_STYLE === ‘uppercase’) {
message = message.toUpperCase();
}
res.json({ message: message });
});
Here is the entire file:
require('dotenv').config();
let express = require('express');
let app = express();
const path = require('path');
app.use('/public', express.static(path.join(__dirname, 'public')));
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname, '/views/index.html'));
});
app.get(‘/json’, function(req, res) {
console.log(“MESSAGE_STYLE:”, process.env.MESSAGE_STYLE);
let message = “Hello json”;
if (process.env.MESSAGE_STYLE === ‘uppercase’) {
message = message.toUpperCase();
}
res.json({ message: message });
});
module.exports = app;
While the .env is only this:
MESSAGE_STYLE=uppercase
I will compare your code to the solution as soon as I can. In the meantime, please confirm where you placed the .env file?
damianodionori:
app.use('/public', expr
some of the quotes you are using are the correct type like this one above
but some are not like this one:
damianodionori:
app.get(‘/json’,
The “curly quotes” are not usable in programming so you have to use the straight ones always.
Once I fixed all the quotes and made a .env file in the root path, I was able to confirm that your code works. Hopefully you can do the same.
damianodionori:
app.use('/public', express.static(path.join(__dirname, 'public')));
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname, '/views/index.html'));
});
app.get(‘/json’, function(req, res) {
console.log(“MESSAGE_STYLE:”, process.env.MESSAGE_STYLE);
let message = “Hello json”;
if (process.env.MESSAGE_STYLE === ‘uppercase’) {
message = message.toUpperCase();
}
res.json({ message: message });
});
module.exports = app;
Thank you very much for your help. Such a dumb mistake! Sorry for wasting your time! I was able to finally complete the challenge.
1 Like
It’s not dumb at all it’s kind of a tricky thing to catch.
One thing to keep in mind is that this form will convert '
to ’ if you don’t enclose your code in triple backticks. So it’s something to watch out of especially if you are copy/pasting back and forth from the forum. Make sure it’s formatted correctly using the backticks or the code format button.
When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>
) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').