Having issue with res.send('Hello Express')

Tell us what’s happening:
I have been having this issue for hours not i don’t know what i have done wrong in my code

the code goes this way:

var express = require('express')
var app = express()

app.get('/', function (req, res) {
  res.send('Hello Express')

still yet having issue with it.
thanks in advance

Your project link(s)

solution: https://replit.com/@yunishello/boilerplate-express

Your browser information:

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

Challenge: Start a Working Express Server

Link to the challenge:

1 Like

You need to export your App, otherwise it won’t build correctly.

There should be a

module.exports = app

at the bottom of your myApp.js file. It should come with the default template I believe.

With that you should see your app working fine.
Hope this helps.

1 Like

thanks for your help :), are you saying I should include it cuz it not provided in the project description and most of the tutorials I have check. if you don’t mind can you help me check this from the official website for Express.js : Writing middleware for use in Express apps

I think I know what the problem is, but don’t know how to resolve it. It the “req” parameter of the function it says “[typescript] ‘req’ is declared but its value is never read”

can you please help me with this cuz I thing its required?

Nothing to do with Express per se, you won’t find it in any tutorial as it’s not part of making a server with express.

That line is needed for FCC to bootstrap your app inside its own controlled environment.
It’s just a requirement from FCC pretty much.

As a matter of fact is inside the starter code for this specific reason, it’s needed internally.

Long(er) explanation.

If you are curios to know more, that line is needed as in server.js, which is the real server starting point, your app is required:

var myApp = require('./myApp');

and then passed into the fcc-express-bground app as argument.

Without the export, that argument is undefined hence the whole server is failing to start up.

Hope this helps :sparkles:

1 Like

Wow it worked just got you clearly thanks for you response :grin:) hoping to be a better developer like you

hello can you please help me out with this i don’t what i have done wrong it was working at first but after some changes it stoppedmodule.exports = app.get("/json", function (req, res) { res.json({ "message": "Hello Json" }) });

thanks for you help

The module should export just app.
The various method will be defined above.



module.exports = app;
1 Like

thanks alot have been able to resolve it :grin:

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