{"id":13809771,"url":"https://github.com/seamapi/nextjs-server-modules","last_synced_at":"2025-10-11T14:30:41.381Z","repository":{"id":41811576,"uuid":"440352202","full_name":"seamapi/nextjs-server-modules","owner":"seamapi","description":"Modules that contain an embedded nextjs server. Used for NextJS server orchestration.","archived":false,"fork":false,"pushed_at":"2025-01-04T03:33:38.000Z","size":1119,"stargazers_count":4,"open_issues_count":21,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-10-01T15:56:17.195Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/seamapi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-12-21T01:14:46.000Z","updated_at":"2024-09-11T17:03:24.000Z","dependencies_parsed_at":"2024-01-15T13:34:57.209Z","dependency_job_id":null,"html_url":"https://github.com/seamapi/nextjs-server-modules","commit_stats":null,"previous_names":["hello-seam/nextjs-server-modules"],"tags_count":62,"template":false,"template_full_name":null,"purl":"pkg:github/seamapi/nextjs-server-modules","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seamapi%2Fnextjs-server-modules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seamapi%2Fnextjs-server-modules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seamapi%2Fnextjs-server-modules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seamapi%2Fnextjs-server-modules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seamapi","download_url":"https://codeload.github.com/seamapi/nextjs-server-modules/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seamapi%2Fnextjs-server-modules/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279007457,"owners_count":26084313,"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","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-08-04T02:00:35.807Z","updated_at":"2025-10-11T14:30:41.085Z","avatar_url":"https://github.com/seamapi.png","language":"TypeScript","readme":"# NextJS Server Modules\n\nA NextJS Server Module is a NextJS project that has been packaged to be easily\nused as an npm module. You might use a server module to...\n\n- Package a \"fake\" or \"mock\" server for easy use in test suites\n- Allow another server to easily \"call into\" your NextJS server\n- Improve the organization of a large project by organizing NextJS servers into\n  server sub-components\n\nThe `nextjs-server-module` cli will help you create a custom nextjs runtime\nto run your projects with, so they can be run without nextjs at runtime.\n\n## Usage\n\nFirst, install with `npm install nextjs-server-modules`\n\nYou can now add a build script or just run `nsm build`\n\nThe build process will output a `.nsm/index.ts` file which can be used to\ncreate your server or invoke requests against it\n\n```ts\nimport myNextJSModule from \"./.nsm\"\n\nconst server = await myNextJSModule({ port: 3030 })\n\n// your server is running on localhost:3030!\n\nserver.close()\n```\n\n### Middlewares\n\nYou can provide middlewares to your server like so:\n\n```ts\nimport myNextJSModule from \"./.nsm\"\n\nconst myMiddleware = (next) =\u003e (req, res) =\u003e {\n  req.token = req.headers.get(\"authorization\").split(\"Bearer \")?.[1]\n  return next(req, res)\n}\n\nconst server = await myNextJSModule({\n  port: 3030,\n  middlewares: [myMiddleware],\n})\n\n// your server is running on localhost:3030!\n\nserver.close()\n```\n\n### Common Scripts\n\nMany times you'll want to add `nsm` when you start testing API endpoints on a\nNextJS project, it makes a lot of sense to use `nextless` and `skip-build` which\nruns a very fast build.\n\n```json\n{\n  \"scripts\": {\n    \"build:test\": \"nsm build --nextless --skip-build --only-api-files\"\n  }\n}\n```\n\n## Internal: How it Works\n\n\u003e Not all NextJS features are currently supported. Particularly:\n\u003e\n\u003e - SSR\n\u003e - getStaticProps\n\nWe build the api endpoints and export static pages with `next build`. We then\nanalyze `.next/server/pages/api` to get all the api routes to server.\n\nWe then construct a main export file that knows how to parse `next.config.js`\nand route to the correct files, which we've statically analyzed and are included\nin the generated `dist/index.js` file.\n\n## Caveats\n\nVercel's Edge Runtime is supported only when running in a Node.js environment. In other words, a bundled nsm project cannot be run in the Edge Runtime.\n\nnsm's implementation of the Edge Runtime does not support:\n\n- [`@vercel/og`](https://www.npmjs.com/package/@vercel/og)\n- `import {userAgent} from \"next/server\"`\n\n## FAQ\n\n### Why can't Next.js bundle into an npm module?\n\nYou can bundle nextjs into npm modules, but some static analysis isn't available\nsince nextjs uses the directory structure to determine what to load in at\nruntime.\n\nYou'll also have problems running a `next` server within a Vercel endpoint,\nbecause some vercel optimizations get rid of some webpack/next modules as an\noptimization.\n\n### Why is my module bigger?\n\nNSM base64 encodes static files so that they're bundleable, it's very inefficient.\n","funding_links":[],"categories":["Official Projects"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseamapi%2Fnextjs-server-modules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseamapi%2Fnextjs-server-modules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseamapi%2Fnextjs-server-modules/lists"}