# AddNextJsApp

- Module: [Aspire.Hosting.JavaScript](/reference/api/go/aspire.hosting.javascript.md)
- Version: `17.0.0`
- Kind: `method`
- Defined on: `DistributedApplicationBuilder`
- Source: [GitHub](https://github.com/microsoft/aspire/tree/bcfa151cdca6d0a573f22d5d9c23f9c727cb3b2f)

Adds a Next.js app to the distributed application builder.

## Remarks

This method configures the Next.js application for both local development and publishing.
In run mode, it starts the Next.js dev server with the correct port binding.
In publish mode, it generates a multi-stage Dockerfile using Next.js standalone output mode,
which copies `public/`, `.next/standalone/`, and `.next/static/` into a
Node.js runtime container.
The Next.js application must have `output: "standalone"` configured in `next.config.ts`
and a `public/` directory (even if empty) for the published container to build correctly.
The following example creates a Next.js app.
```
var builder = DistributedApplication.CreateBuilder(args);
builder.AddNextJsApp("frontend", "./frontend");
builder.Build().Run();
```

## Definition

```go
func (DistributedApplicationBuilder) AddNextJsApp(
    name string,
    appDirectory string,
    options ...*AddNextJsAppOptions,
) NextJsAppResource
```

## Parameters

- `name` (`string`) -- The name of the Next.js app.
- `appDirectory` (`string`) -- The path to the directory containing the Next.js app.
- `options` (`...*AddNextJsAppOptions`) -- optional settings, see [Options](#options)

## Options

Optional parameters are passed in a trailing `options ...*AddNextJsAppOptions` argument.

- `RunScriptName` (`*string`) -- The name of the script that runs the Next.js dev server. Defaults to "dev".

## Returns

[`NextJsAppResource`](/reference/api/go/aspire.hosting.javascript/nextjsappresource.md) -- The resource builder.

Returns a handle; failures surface later via `Err()`.

## Applies to

- `DistributedApplicationBuilder`
