# Next Post — Node

**URL:** <https://community.prismic.io/t/next-post-node/7589>\
**Category:** Developing with Prismic\
**Tags:** nodejs\
**Created:** [October 24, 2021, 1:46pm UTC](https://community.prismic.io/t/next-post-node/7589 "2021-10-24T13:46:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kero](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/kero/32/3148_2.png) [@Kero](https://community.prismic.io/u/Kero)\
**Post date:** [October 24, 2021, 1:46pm UTC](https://community.prismic.io/t/next-post-node/7589/1 "2021-10-24T13:46:17Z")

</div>

Hello guys, I'm trying to create a "next button" for the posts on my site but when I reach the last post I get an error, anyhow I can get the first post when there's no more posts left?

```auto
app.get('/detail/:uid', async (req, res) => {
  const api = await initApi(req)
  const work = await api.getByUID('work', req.params.uid)
  const nextwork = await api.query(Prismic.Predicates.at('document.type', 'work'), { pageSize : 1 , after : `${work.id}`, orderings: '[my.work.date desc]'})

  res.render('pages/detail', {
    work,
    nextwork
  })
})

```

Thanks!

---

<div class="post-metadata">

**Author:** ![Priyanka](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/priyanka/32/3223_2.png) [@Priyanka](https://community.prismic.io/u/Priyanka)\
**Post date:** [October 27, 2021, 9:23am UTC](https://community.prismic.io/t/next-post-node/7589/5 "2021-10-27T09:23:54Z")

</div>

Hello @Kero

Welcome to the Prismic community, and thanks for reaching out to us.

If I understand your question well, you want to use the first post in case there is no post left. In this case, you will have to send a new query to retrieve the first result when the last post is retrieved from the query.

Steps:

1. Check if the result\_size is zero or not.
2. If it is zero, then send a new request for retrieving the first element. (by removing the after parameter from the query and setting page size as 1)
3. If it is not zero, then retrieve the result.

Let me know if you have any further questions.

Thanks,  
Priyanka

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/system/32/1746_2.png) [@system](https://community.prismic.io/u/system)\
**Post date:** [November 2, 2021, 8:07am UTC](https://community.prismic.io/t/next-post-node/7589/6 "2021-11-02T08:07:24Z")

</div>

closed on November 2, 2021, 8:07am UTC as resolved,  flag & select 'Something Else' to reopen.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/system/32/1746_2.png) [@system](https://community.prismic.io/u/system)\
**Post date:** [December 9, 2021, 3:20pm UTC](https://community.prismic.io/t/next-post-node/7589/7 "2021-12-09T15:20:31Z")

</div>

Opened on December 9, 2021, 3:20pm UTC


