App.get for basic Node and Express - Start a Working Express Server

Tell us what’s happening:
I am on Basic Node and Express - Start a Working Express Server and am super confused about what req and res stand for and if i am suppose to put the HTTP address of the replit code is producing before the ,function(req, res) or is that suppose to be the req or res?

Your code so far

Your browser information:

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

Challenge: Start a Working Express Server

Link to the challenge:

Welcome, seth.

Handlers take the form function(req, res) {...} , where req is the request object, and res is the response object.

If you want a lot more information than that, then I recommend you read the official docs for Express: Express 4.x - API Reference (expressjs.com)

I am not too sure what you mean by this. So, I might be going off on a tangent with this:

Let’s serve our first string! In Express, routes takes the following structure: app.METHOD(PATH, HANDLER) .

This means, a common form of setting up app route logic is:

app.get('/relative-path', handler);
// We just learnt what a handler is:
function handler(req, res) {
  // Logic...
}

So, keep in mind, the path is relative. This means, for a route like this very forum page we are on, the route logic might look like this:

app.get('/t/app-get-for-basic-node-and-express-start-a-working-express-server',  (req, res) => {
  // I like arrow functions for anonymous functions (the handler function above),
  // but do not get hung up on it
  // In here is the logic to return, in a response, the data for this page
  // silly example:
  return res.json({postTitle: "App.get for basic Node and Express - Start a Working Express Server"});
  // You DO NOT need the 'return' keyword (in this case), but I like being explicit.

If you have any more specific questions, be sure to use the official docs, and ask here for clarification.

Hope this helps

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