Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

243
Views
How to gracefully shut down nuxt.js + serverMiddleware + express after an unhandled rejection

TLDR: Is there a way to programmatically and properly shut down the Nuxt server while in the serverMiddleware?


I recently learned how create my own API inside Nuxt 2 through serverMiddleware. Before knowing serverMiddleware, I had to run my API in a separate backend. So I think I'm familiar with handling unhandled rejections.

Here's an example of my express backend code:

const express = require('express')
const app = express()

const port = process.env.PORT

const server = app.listen(port, () => {
    console.log(`App is running on port ${port}`)
}) 

process.on("unhandledRejection", (err) => {
    console.log(err.name, err.message);
    console.log("Unhandled Rejection. Shutting Down.");
    server.close(() => {
      process.exit(1);  
    });
});

Now when using Nuxt, app.listen() and server.close() doesn't work because Nuxt is running its own server. While process.exit(1) does the job, from what I understand, that by itself isn't ideal.

Is there a way to programmatically and properly shut down the Nuxt server while in the serverMiddleware?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!