TypeError: Cannot read property 'env' of undefined

Tell us what’s happening:

Your project link(s)

solution: http://localhost:3000

Your browser information:

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

Challenge: Use the .env File

Link to the challenge:

what issue are you having? also please provide your code, otherwise it’s impossible to know what’s going on

This is my app.js page code its working fine but when i click test completed button its not completed

var express = require("express");
var app = express();
var response = "uppercase";
// --> 7) Mount the Logger middleware here

// --> 11) Mount the body-parser middleware here

/** 1) Meet the node console. */
console.log("Hello World");

/** 2) A first working Express Server */

/** 3) Serve an HTML file */
app.get("/", function(req, res) {
res.sendFile(__dirname + "/views/index.html");
});

/** 4) Serve static assets */
app.use(express.static("public"));

/** 5) serve JSON on a specific route */
app.get("/json", function(req, res) {
if (process.env.MESSAGE_STYLE === "uppercase") {
message = "Hello json".toUpperCase();
res.json({
"message": "Hello json".toUpperCase()
});
} else {
message = "Hello json";
}

});

/** 6) Use the .env file to configure the app */

/** 7) Root-level Middleware - A logger */
// place it before all the routes !

/** 8) Chaining middleware. A Time server */

/** 9) Get input from client - Route parameters */

/** 10) Get input from client - Query parameters */
// /name?first=<firstname>&last=<lastname>

/** 11) Get ready for POST Requests - the `body-parser` */
// place it before all the routes !

/** 12) Get data form POST */

// This would be part of the basic setup of an Express app
// but to allow FCC to run tests, the server is already active
/** app.listen(process.env.PORT || 3000 ); */

//---------- DO NOT EDIT BELOW THIS LINE --------------------

module.exports = app;

Hello there,

As far as I can tell, it appears you are using the old boilerplate code (from last year) to complete this. This might not be causing any issue with the tests, but it is recommended to use the latest boilerplate, as the tests rely on it.

Otherwise, walk me through what you think this code is doing:

if (process.env.MESSAGE_STYLE === "uppercase") {
  message = "Hello json".toUpperCase();
  res.json({
  "message": "Hello json".toUpperCase()
  });
} else {
  message = "Hello json";
}

Also, I’ve edited your post for readability. 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 (’).

what’s your .env file content?

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