Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Why is my offset NaN? Everything works fine when I comment offset out of the find options. I know there are other questions like this, but none of them solve the problem.

exports.getProducts = (req, res, next) => {
let limit = 10, //10 products per page
    offset = 0; //no products skipped
Product.findAndCountAll()
    .then((data) => {
        let page = req.params.page ? parseInt(req.params.page) : 1,
            pages = Math.ceil(data.count / limit);
        offset = limit * (page - 1);
        console.log(offset)  //NaN
        console.log(typeof offset)  //number
        Product.findAll({
                limit: limit,
                offset: offset,
                include: [{
                    model: Order,
                    as: 'orders'
                    model: User,
                    as: 'user'
                If req.params.page is a string like 'anything' then parseInt(req.params.page) is NaN and offset is NaN as well
– Konrad
                Feb 27 at 17:59
                here is the url localhost:3000/search/1 how its gonna be string like that & i set fallback 1 if its not exist i can't catch the place it happens
– Natnael Tibebu
                Feb 27 at 18:11
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.