borel
February 22, 2023, 6:21am
1
let express = require('express');
let app = express();
//console.log("Hello World");
app.use("/public",express.static('public'))
app.get("/json", function(req, res) {
res.json({"message": "Hello json"});
//res.sendFile ( __dirname + "/views/index.html");
})
hello please i need your help
hbar1st
February 22, 2023, 11:16am
2
Please edit your post and add a link to the challenge and a description of what you need help with.
borel
February 22, 2023, 12:54pm
3
https://replit.com/@bowak/boilerplate-express-13#myApp.js
that is it
borel
February 22, 2023, 1:01pm
4
https://replit.com/@bowak/boilerplate-express-13#myApp.js
borel
February 22, 2023, 1:02pm
5
let express = require('express');
let app = express();
//console.log("Hello World");
app.use("/public",express.static('public'))
app.get("/json", (req, res) => {
const mySecret=process.env["MESSAGE_STYLE"]
if(mySecret === "uppercase"){
res.json({"message": "HELLO JSON"});
}else{
res.json({"message": "Hello json"});
};
res.sendFile ( __dirname + "/views/index.html")
})
Are you doing this on replit? If so, could you give a link to your code on there please? (The url in the address bar for the repl).
Sky020
February 22, 2023, 8:34pm
7
I’ve edited your code 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 (').
When I visit your /json
endpoint, I get the response { message: 'Hello json' }
, when I’d expect to get { message: 'HELLO JSON' }
.
Have you saved your MESSAGE_STYLE variable correctly in your Secrets tab?
Also, you appear to have altered your code from the previous steps, as the console is throwing errors.
You should be serving index.html
via the root (/
).