Menu Close

How to delay an http response in ExpressJS

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.

Posted in expressjs, node