I faced issues using .env file for the task " Use the .env File" and after many hours of debugging I finally able to resolve. Here are the solution that might help others:
- Make sure you have installed dotenv module.
npm i dotenv
- Add the dotenv module in myApp.js
const path = require('path')
require('dotenv').config({ path: path.resolve(__dirname, './.env') });
Your code so far
app.get("/json", function (req, res) {
if (process.env.MESSAGE_STYLE === 'uppercase') {
res.json({
"message": "HELLO JSON"
});
}
res.json({
"message": "Hello json"
});
});
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36
Challenge: Use the .env File
Link to the challenge: