Basic Node and Express - Use the .env File

Tell us what’s happening:

This is my myApp.js file :

let express = require('express');

let app = express();

app.get('/json', (req,res) => {
    res.json({"message": "HELLO JSON"});
    else res.json({"message": "Hello json"});

this is what in my dot env file given below savedd as .env:


It should be working but it is not . why ? by the when I console (process.env.MESSAGE_STYLE === ‘uppercase’) in the route handler it shows false. why?

Your code so far

Your browser information:

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

Challenge Information:

Basic Node and Express - Use the .env File

your .env file should not contain semicolons ;

Create a .env file in the root of your project directory, and store the variable MESSAGE_STYLE=uppercase in it.

In a .env file the format of environment variables is KEY=VALUE on each line.

1 Like

also remember you need to restart the server after any changes

1 Like