Tell us what’s happening:
I tried to send json file with “uppercase” if environment variable process.env.MESSAGE_STYLE = uppercase. But I get an error. I tried several times but I couldn’t get it to work Some help please?
If you’ll give me a link to more examples like this I would appreciate it even more
Your code so far
var express = require(‘express’);
var app = express();
const port = process.env.PORT;
process.env.MESSAGE_STYLE=“uppercase”
I moved the env variable to the file .env but it didn’t help me
I still couldn’t pass my test. I got 0 errors
app.get(’/json’, (req, res) => {
if(process.env.MESSAGE_STYLE === ‘uppercase’){
return res.json({
message: ‘Hello json’.toUpperCase()
});
}else{
return res.json({
message: ‘Hello json’})
}
});
Aaaand I solved it…
I forgot to delete “process.env” from the .env file so the only thing I had left was variable name and declaration MESSAGE_STYLE=uppercase
After that my code worked just fine:
app.get(’/json’, (req, res) => {
if(process.env.MESSAGE_STYLE === ‘uppercase’){
return res.json({
message: ‘Hello json’.toUpperCase()
});
}else{
return res.json({
message: ‘Hello json’})
}
});