0

Hi Im starting to learn how apis works and got my first stucktrace. The thing is that Im trying this code

const app = require('express')();

const PORT = 8080;


app.get('/tshirt', (req , res) => {
    res.status(200).send({
        tshirt: 'blue',
        size: 'large'
    })
});

But Insomnia show me "Cannot GET /tshirt" and 404 at 'http://localhost:8080/tshirt'

So my question is why this doesnt work?

Additional information: On firefox I cant run 'http://localhost:8080/tshirt' instead I have to run 'localhost:8080/tshirt'. But on Insomnia I cant test 'localhost:8080/tshirt' and have to run 'http://localhost:8080/tshirt'.

1 Answers1

1

1.As far as I know, using Promises, it's will your help. please try this.

const getTshirt = async (req, res) => {
    res.status(200).send({
        tshirt: 'blue',
        size: 'large'
    })
};
app.get('/tshirt', getTshirt);
  • Good practice but dont solve my problem, anyway I will implement it in future productions – Lucas Vega May 19 '22 at 08:52
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 20 '22 at 01:27