To use morgan as logging middleware for Nuxt 3, run npm install morgan
, then create the file /server/middleware/morgan.ts
with the following contents:
import morgan from "morgan";
export default defineEventHandler((event) => {
var logger = morgan("tiny");
logger(event.node.req, event.node.res, function () {});
});
You should then get output on the server console similar to the following (for the tiny format specified above, and assuming you have /server/api/search.get.ts
defined and working):
GET /api/search?term=123 200 - - 169.540 ms
You can then change the morgan format to get more extensive logging if required.