0

I was trying to create a middleware function for my object and I ran across this code. I was wondering the complete syntax of this code.

I understand that this makes a get request to the router named "test". Afterwards, when it executes the function that takes (req, res) inputs and if it is successful it outputs a response message object "user works"

Is my understanding correct?

    // sends it to the route /test
    router.get("/test", (req, res) => res.json({msg: "Users Works"}));
  • Doesn't that just *handle* requests to `/test`? – CertainPerformance Sep 15 '18 at 09:48
  • Thanks @CertainPerformance How would that be explained in terms of the syntax? – Alfonso Torres Sep 15 '18 at 10:48
  • `.get` means "handle GET requests", `"/test"` means "sent to the route mydomain.com/test", the callback is executed when a request of type GET is sent to the route /test. `req` is the request data when a connection is made - who made it and such, `res` is the result being sent back. – VLAZ Sep 15 '18 at 10:58

0 Answers0