{"id":13672892,"url":"https://github.com/egoist/nest-next","last_synced_at":"2025-04-30T16:28:46.351Z","repository":{"id":45275472,"uuid":"231882725","full_name":"egoist/nest-next","owner":"egoist","description":"Nest module for Next.js","archived":false,"fork":false,"pushed_at":"2023-01-07T13:24:34.000Z","size":1648,"stargazers_count":38,"open_issues_count":16,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T17:51:12.216Z","etag":null,"topics":["api","nestjs","nextjs","nodejs","react","ssr","universal"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/egoist.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-05T07:25:08.000Z","updated_at":"2022-11-12T22:54:12.000Z","dependencies_parsed_at":"2023-02-07T06:45:55.950Z","dependency_job_id":null,"html_url":"https://github.com/egoist/nest-next","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Fnest-next","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Fnest-next/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Fnest-next/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Fnest-next/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/egoist","download_url":"https://codeload.github.com/egoist/nest-next/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251741907,"owners_count":21636341,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","nestjs","nextjs","nodejs","react","ssr","universal"],"created_at":"2024-08-02T09:01:55.324Z","updated_at":"2025-04-30T16:28:46.035Z","avatar_url":"https://github.com/egoist.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Nest module for Next.js\n\nUse [Next.js](https://nextjs.org/) with a [Nest.js](https://nestjs.com/) server.\n\n## Why?\n\nAllow you to manage both your frontend and backend in a single repository. And you maintain one domain `example.com` instead of two: `example.com` and `api.example.com`.\n\n## Install\n\n```bash\nyarn add @nest-module/next next react react-dom\n\n# Following typings are also needed\nyarn add @types/react @types/node --dev\n```\n\n## Usage\n\nIn your `src/app.module.ts`:\n\n```ts\nimport { join } from 'path'\nimport { NextModule } from '@nest-module/next'\n\n@Module({\n  imports: [\n    NextModule.register({\n      dev: process.env.NODE_ENV !== 'production',\n      // It's recommended to populate your Next.js app in a sub directory \n      // like ./next folder so that it could use its own tsconfig.json\n      dir: join(__dirname, '../next')\n    })\n  ]\n})\nexport class AppModule {}\n```\n\nThen you can use file-system based routing, try populating a page at `next/pages/index.tsx`:\n\n```tsx\nexport default () =\u003e \u003cdiv\u003eHello Next!\u003c/div\u003e\n```\n\nAnd configure your root `tsconfig.build.json` to include `src` folder only:\n\n```json\n{\n  \"include\": [\"src\"]\n}\n```\n\nNext.js will automatically create another TS config file at `next/tsconfig.json`, we want the root TS config to be applied to your Nest server only.\n\nNow start your Nest server and navigate to the homepage and you will see `Hello Next!`.\n\n### Manually render a page\n\nBesides automatic routing via `pages` folder, you can also use `res.nextRender` inside a Nest route handler to render a Next.js page:\n\n```js\nimport { Res, Controller, Get } from '@nestjs/common'\nimport { Response } from 'express'\n\n@Controller()\nexport class AppController {\n  @Get('/some-page')\n  anotherPage(@Res() res: Response) {\n    res.nextRender('/another-page', {\n      // optional route query\n      message: 'another page'\n    })\n  }\n}\n```\n\nThis route handler will render `pages/another-page.tsx`:\n\n```tsx\nconst AnotherPage = ({ query }) =\u003e {\n  return \u003cdiv\u003e{query.message}\u003c/div\u003e\n}\n\n// `getInitialProps` is required if you want to access `query` in your page component\nAnotherPage.getInitialProps = ctx =\u003e {\n  return { query: ctx.query }\n}\n\nexport default AnotherPage\n```\n\n## License\n\nMIT.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegoist%2Fnest-next","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fegoist%2Fnest-next","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegoist%2Fnest-next/lists"}