Tell us what’s happening:
Have trouble waking up and didn’t know if my code was the problem on replit.
Your code so far
let express = require('express');
let app = express();
console.log("Hello World")
// app.get('/', (req, res)=>{
// res.send('Hello Express')
// })
app.get("/", (req, res) =>{
res.sendFile(__dirname + "/views/index.html")
})
app.use('/public', express.static(__dirname + "/public"))
// let message= {"message": "Hello json"}
const mySecret = process.env['MESSAGE_STYLE']
// app.get('/json',(req, res) => {
// res.json(message)
// })
let message = {"message": "Hello json"}
app get('/json', req, res)=>{
If(process.env.mySecret === "uppercase"){
res.json({"message": "HELLO JSON"})
}else{
res.json(message)
}
}
module.exports = app;
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36 Edg/103.0.1264.49
Challenge: Basic Node and Express - Use the .env File
Link to the challenge:
ok, fix those but the npm still doesn’t start.
let express = require('express');
let app = express();
console.log("Hello World")
// app.get('/', (req, res)=>{
// res.send('Hello Express')
// })
app.get("/", (req, res) =>{
res.sendFile(__dirname + "/views/index.html")
})
app.use('/public', express.static(__dirname + "/public"))
// let message= {"message": "Hello json"}
// app.get('/json',(req, res) => {
// res.json(message)
// })
let message = {"message": "Hello json"}
app.get('/json', req, res)=>{
if(process.env.MESSAGE_STYLE === "uppercase"){
res.json({"message": "HELLO JSON"})
}else{
res.json(message)
}
}
module.exports = app;
Got it to work but it’s not passing for some reason
camperextraordinaire:
npm install https://github.com/freeCodeCamp/fcc-express-bground-pkg.git
Look like the next one doing the same thing:
fcc-learn-node-with-express@0.1.0 start
node server.js
Hello World
Node is listening on port 3000…
*
GET / _ 74.211.3.138
*
GET /public/style.css _ 74.211.3.138
*
GET / _ 63.160.159.164
*
GET /public/style.css _ 63.160.159.164
Learn to Code — For Free
*
GET /json _ 35.247.44.72
Should be Working
My repLIT
Look carefully at the format of the output expected:
GET /json - ::ffff:127.0.0.1
You are returning:
GET /json _ ::ffff:127.0.0.1
whoopsie hit the shift button when I shouldn’t.
system
Closed
January 14, 2023, 12:53pm
16
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.