Please help.
I have done this lesson - the only way I could get it to work was to comment out my previous code - so my code looks like this:
Spoiler
const mySecret = process.env['MESSAGE_STYLE']
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'));
// app.use((req, res, next) => {
// console.log(req.method + " " + req.path + " - " + req.ip);
// next();
// });
// app.get('/json', (req, res) => res.json(process.env.MESSAGE_STYLE == 'uppercase' ? {"message": "HELLO JSON"} : {"message": "Hello json"}));
// app.get('/now', function(req, res, next) {
// req.time=new Date().toString();
// next();
// },
// function(req, res, next) {
// res.json({"time": req.time});
// }
// );
app.get("/:word/echo", (req, res) => {
res.json({
"echo": req.params.word
});
});
module.exports = app;
I have two questions here:
- How do I see my results? my link is https://boilerplate-express.alanbra.repl.co and I tried looking at https://boilerplate-express.alanbra.repl.co/echo and https://boilerplate-express.alanbra.repl.co/freecodecamp/echo but both just showed Not Found
- Why didn’t my code work without commenting out my previous code - the lesson didn’t say anything about this - I only commented it out after someone on the forum had said they’d commented out their code
Thank you
Alan