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));

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay