nitrojs / nitrojs/nitro

Export `nitroApp` instance

Open
#3,579 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discussion enhancement v2
Dominant language
TypeScript
Stars
11.2k
Forks
899
Avg merge
2d 24m
Merged PRs (30d)
40

Description

Describe the feature

Context: #3578 (@markthree)

I am currently developing a zero-downtime API service based on H3 and several Nitro applications. I've found that exporting NitroApps might be more user-friendly, as users may need to access their internal options or perform certain actions (such as invoking shutdown hooks).

Example

// plugins/db.ts
// ignore some codes
export default defineNitroPlugin((nitro) => {
    nitro.hooks.hook("close", async () => {
        const db = await useDB();
        db.close();
   });
})
// user case
import("./.output/server/index.mjs").then(({ nitroApp }) => {
   // ignore some codes
   nitroApp.hooks.callHook("close");
})
Additional information
  • Would you be willing to help implement this feature?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the generated server entry point .output/server/index.mjs and trace how the Nitro application instance is created and exported. Verify that importing the entry point exposes nitroApp and that its hooks can be invoked as shown; the feature is complete when this public export works for generated Nitro applications.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.