# nx-next-server

> NX Next Server

Latest version **1.0.0** (published 2020-12-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install nx-next-server
pnpm add nx-next-server
yarn add nx-next-server
bun add nx-next-server
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-12-31 |
| First published | 2020-09-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Ari Seyhun |
| Maintainers | acidic9 |
| Keywords | Nx, Next.js, Custom server, TypeScript |

## Links

- npm: https://www.npmjs.com/package/nx-next-server
- Repository: https://github.com/acidic9/nx-next-server
- Homepage: https://github.com/acidic9/nx-next-server#readme
- Issues: https://github.com/acidic9/nx-next-server/issues
- npm.io page: https://npm.io/package/nx-next-server

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2020-12-31
- 0.1.3 — 2020-09-25
- 0.1.2 — 2020-09-24
- 0.1.1 — 2020-09-23
- 0.1.0 — 2020-09-23

## README

# Nx Next Server

> Utility for creating a custom Next.js server with Nx in a separate app.

![npm](https://img.shields.io/npm/v/nx-next-server)

Creating [Next.js](https://nextjs.org/) custom servers with [Nx](https://nx.dev/) is not possible (as of the time this package was created). `nx-next-server` provides a simple utility function which can be used to start a Next.js app within Nx from another Nx app.

The benefits of this are:

- Create custom Next.js server with TypeScript in Nx
- Import and use Nx libs within custom server

## Install

```bash
$ yarn add nx-next-server
# or
$ npm install nx-next-server
```

## Usage

Your NX workspace should include a [Next.js app](https://nx.dev/react/plugins/next/overview) and a server app ([Node.js](https://nx.dev/react/plugins/node/overview)/[Express](https://nx.dev/react/plugins/express/overview)).

This example assumes you have a Nx workspace with two apps:

- **apps/web** - Next.js app
- **apps/server** - Express app

```ts
// apps/server/src/main.ts
import createServer from "nx-next-server";
import * as express from "express";

// Create Next.js server for apps/web app
createServer("web").then(({ nextApp, handler, settings, proxyConfig }) => {
  const server = express();

  server.all("*", (req, res) => handler(req, res));

  server.listen(settings.port, settings.hostname, () => {
    console.log(
      `Listening on ${settings.hostname || "http://localhost"}:${settings.port}`
    );
  });
});
```

Once you've written your express app, it can be run using:

```bash
$ yarn start server
```

## Build

Your Next.js app can be built with:

```bash
$ yarn build web
```

Your Express server can be built with:

```bash
$ yarn build server --configuration=production
```

> **Note:** you need to include `--configuration=production` to ensure your server targets the `dist/apps/web` Next.js build.

The build can be tested by running the main.js file in `dist`:

```bash
$ node ./dist/apps/server/main.js
```

## License

[MIT](http://vjpr.mit-license.org)

---
_Source: https://npm.io/package/nx-next-server · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
