Registry Mirror
Skip to content

support for running nitro tasks #992

Closed as duplicate
Closed as duplicate

Description

@IlyaSemenov

Problem

As a full-stack Nuxt developer, I would like to have a way to execute commands within Nuxt's compilation context (with all imports and aliases functioning identically to Nuxt server code). A common use case would be running database migration scripts with arguments (e.g., migrate up, migrate rollback). Another example is running a development-time script to populate/update server assets (e.g. download and parse some external database, using common code and types under server/).

Current workaround

Currently, what I do is:

  1. Create a special API endpoint (e.g., /api/scripts/migrate)
  2. Make it parse HTTP POST data to handle migration commands
  3. Add security with a secret token (disable checks in dev mode for convenience)
  4. Create a npm script that hardcodes certain port:
{
  "scripts": {
    "migrate": "curl localhost:3000/api/scripts/migrate -d"
  }
}

This approach is cumbersome and introduces unnecessary complexity.

Proposed solution

  • In dev mode: nuxt run migrate -- up (executing server/scripts/migrate.ts)
  • In production mode: nuxt build would either compile each script to a separate entrypoint (such as .output/scripts/migrate.js), or perhaps the single server.js could run scripts with node .output/server.js run migrate -- up.

I had long assumed #62 was meant to cover this use case, only to discover (after its closing) that it never actually had ;-)

Additional information

  • Would you be willing to help implement this feature?
  • Could this feature be implemented as a module?

Final checks

Activity

  1. OrbisK commented on Jul 28, 2025

    @OrbisK
    Member

    I think you are looking for: https://nitro.build/guide/tasks

  2. IlyaSemenov commented on Jul 28, 2025

    @IlyaSemenov
    Author

    Maybe I am, but I don't think this is exposed in Nuxt, or is it?

    % pnpm nuxt task list
    Nuxt CLI (nuxi v3.23.0)
    ...
     ERROR  Unknown command task
    

    The Nitro tasks are also quite limited (e.g. no production build runners at the moment), but if Nuxt at least re-exposed them, that would be a great start.

  3. danielroe commented on Jul 28, 2025

    @danielroe
    Member

    that would be a nice idea!

    I'd like to see them stabilised first (so the API wouldn't change - cc: @pi0) and yes, being able to run tasks on build/deploy would be great.

    this is how I currently work around that issue on my own site

  4. transferred this issue fromnuxt/nuxton Jul 28, 2025
  5. changed the title [-]Running custom CLI scripts within Nuxt compilation context[/-] [+]support for running nitro tasks[/+] on Jul 28, 2025
  6. ineshbose commented on Dec 20, 2025

    @ineshbose
    Member

    Btw, integration with Nitro Tasks may be getting tracked in #353

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions