Search code examples
node.jsexpresshttprequestaxios

Difference between express.js and axios.js in Node


We use axios for http requests such as get, post, etc. We use express for the same purpose also. However according to what I read, they are for different purposes. Please explain how.

PS: If you explain it by giving an example, it would be great!


Solution

  • You can think of express.js as a warehouse:

    app.get('/item/:name', async function (req, res) {
      res.send(await findItemByName(req.params.name));
    });
    

    If you want to get an item, for example a pencil, from this warehouse, you can use axios.js.

    axios.get('/item/pencil')