DEV Community

Cover image for How to delay an http response in ExpressJS
Adrian Matei for Codever

Posted on • Edited on • Originally published at codever.dev

2 1

How to delay an http response in ExpressJS

Project: Codever

Enclose the response in setTimeout

router.get('/', async (request, response) => {

  const {page, limit} = PaginationQueryParamsHelper.getPageAndLimit(request);
  const bookmarks = await PublicBookmarksService.getLatestPublicBookmarks(page, limit);

  setTimeout((() => {
    return response.send(bookmarks);
  }), 2000)
});
Enter fullscreen mode Exit fullscreen mode

Shared with ❤️ from Codever. Use 👉 copy to mine functionality to add it to your personal snippets collection.

Top comments (1)

Collapse
 
hakki profile image
Hakki • Edited

await new Promise(resolve => setTimeout(resolve, 2000));

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay