title: How to do sorting in nodejs in backend
body: <p>This is my node Api</p>
  
  <pre><code>router.post("/*****", async function(req, res, err) {
    let limit = 5;
    let offset = 0;
    tblAdmin
      .findAndCountAll()
      .then(data =&gt; {
        console.log("hello world", req.body);
        let page = (req.body.page &amp;&amp; req.body.page) || 1;
        let sortfield = req.body.sortfield;
        let sortOrder = req.body.sortOrder;
        let pages = Math.ceil(data.count / limit);
        offset = limit * (page - 1);
        tblAdmin
          .findAll({
            attributes: ["id", "firstName", "lastName", "status", "email"],
            limit: limit,
            offset: offset
            // order: [`firstName`, `DESC`]
            // $sort: { id: 1 }
          })
          .then(users =&gt; {
            res.status(200).json({
              status: 1,
              message: "Data has been retrieved",
              result: users,
              count: data.count,
              pages: pages
            });
          });
        // res.status(200).json({
        //   status: 1,
        //   message: "Data has been retrieved",
        //   data: data.map(result =&gt; {
        //     return {
        //       id: result.id,
        //       firstName: result.firstName,
        //       lastName: result.lastName,
        //       status: result.status,
        //       email: result.email
        //     };
        //   })
        // });
      })
      .catch(err =&gt; {
        res.status(500).json({
          status: 0,
          message: "Data is not retrieved from database"
        });
      });
  });
  </code></pre>
  
  <p>and this is my react front end </p>
  
  <pre><code>axios.post(`http://abc/**`, params).then(res =&gt; {
        const pagination = { ...this.state.pagination };
        let apiData = res.data.result;
        console.log("Data", apiData);
        console.log("params", params);
        if (res.data.status === 1) {
          const objects = apiData.map(row =&gt; ({
            key: row.id,
            id: row.id,
            firstName: row.firstName,
            lastName: row.lastName,
            status: row.status,
            email: row.email
          }));
          console.log(res.data);
          pagination.total = res.data.count;
          this.setState({
            loading: false,
            data: objects,
            pagination
          });
        } else {
          console.log("Database status is not 1!");
        }
      });
  </code></pre>
  
  <p>now this is shown on a table and when i select the field of table in front end it should show ascending or descending order i need to do that order in backend.
  from front end i m sending param which includes pagination, sortfield and sortorder and i m getting that in backend now what should i do to change the table according to my order?</p>