Basic Node and Express - Use the .env File

Tell us what’s happening:

I keep seeing this error and I’m not sure what to do.

[Error: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /_api/use-env-vars</pre>
</body>
</html>
]

Your Code So Far

const express = require('express');
const cors = require('cors');
const app = express();

require('dotenv').config()

app.use(cors());

app.get('/json', (req, res, next) => {
  var response = "Hello json";
  if (process.env.MESSAGE_STYLE === "uppercase") {
    response = "Hello json".toUpperCase();
  } else {
    response = "Hello json";
  }
  res.json({ message: response })

})

app.listen(3100, () => { // Make your API live
  console.log('Express server initialized');
});

Your project link(s)

solution: boilerplate-npm - Replit

Your browser information:

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

Challenge Information:

Basic Node and Express - Use the .env File

You are using the wrong repl for this challenge.
You should be using the boilerplate-express repl for all of these challenges (as linked in the challenge description in the first step).

1 Like

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