{"id":25212983,"url":"https://github.com/arunkumar201/nextjs-self-host-starter","last_synced_at":"2026-04-20T03:35:04.848Z","repository":{"id":259913446,"uuid":"878895823","full_name":"arunkumar201/nextjs-self-host-starter","owner":"arunkumar201","description":"nextjs-self-host-starter","archived":false,"fork":false,"pushed_at":"2024-10-28T14:48:35.000Z","size":239,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-10T15:18:33.849Z","etag":null,"topics":["docker","nextjs","shell-script"],"latest_commit_sha":null,"homepage":"","language":"Shell","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/arunkumar201.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-26T12:06:32.000Z","updated_at":"2024-11-20T16:21:46.000Z","dependencies_parsed_at":"2024-10-28T17:55:40.843Z","dependency_job_id":null,"html_url":"https://github.com/arunkumar201/nextjs-self-host-starter","commit_stats":null,"previous_names":["arunkumar201/nextjs-self-host-starter"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arunkumar201%2Fnextjs-self-host-starter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arunkumar201%2Fnextjs-self-host-starter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arunkumar201%2Fnextjs-self-host-starter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arunkumar201%2Fnextjs-self-host-starter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arunkumar201","download_url":"https://codeload.github.com/arunkumar201/nextjs-self-host-starter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247305906,"owners_count":20917202,"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":["docker","nextjs","shell-script"],"created_at":"2025-02-10T15:18:35.694Z","updated_at":"2025-10-15T22:43:38.049Z","avatar_url":"https://github.com/arunkumar201.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).\n\n## Getting Started\n\nFirst, run the development server:\n\n```bash\nnpm run dev\n# or\nyarn dev\n# or\npnpm dev\n# or\nbun dev\n```\n\nOpen [http://localhost:3000](http://localhost:3000) with your browser to see the result.\n\nYou can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.\n\n# Run using Docker web service (prod)\n\n- Build the docker image\n\n```bash\ndocker build -t self-host-nextjs ./\n```\n\n- Run the docker container\n\n```bash\ndocker run -p 3000:3000 -d self-host-nextjs\n```\n\n# Run app with all service using Docker\n\n```bash\npnpm docker:start\n```\n\n# Prisma setup\n\n- Installing Prisma\n\n```bash\npnpm install -D prisma\npnpx prisma init\n\n```\n\n## Configuring Prisma\n\n- once we ran `pnpx prisma init` cmd it will add the `schema.prisma` and `.env` file with default code and DATABASE_URL env variable.\n\n- easiest way to install the postgres database is to use the `docker` container\n\n```bash\ndocker pull postgres\n```\n\n- start a Postgres instance by running the command below\n\n```bash\ndocker run --name my-postgres -e POSTGRES_USER=root -e POSTGRES_PASSWORD=myuser -e POSTGRES_DB=mydb -p 5432:5432 -d postgres\n\n```\n\n- now we need to configure the `DATABASE_URL` env variable in the `.env` file\n\n```bash\nDATABASE_URL=\"postgresql://root:myuser@localhost:5432/mydb\"\n```\n\n- now we can run the `prisma migrate dev` command to create the tables in the database\n\n```bash\npnpx prisma migrate dev --name init\n\n```\n\n- Check the Migration Status\n\n```bash\npnpx prisma migrate status\n```\n\n- Generate Prisma Client - generates the Prisma client in the node_modules directory, enabling us to use it to interact with your updated database schema.\n\n```bash\npnpx prisma generate\n```\n\n- We can also run Prisma Studio, a visual editor for your database\n\n```bash\npnpx prisma studio\n```\n\n## Creating the prisma client to interact with the database in nextjs application\n\n- we can directly using Prisma Client in various parts of your application to interact with the database\n  but it is not the most efficient or optimal approach, especially for a server-side environment like Next.js.\n\n- insted,we need to create a dedicated module that ensures Prisma Client is used as a singleton across your application. it is crucial for maintaining efficient and reliable database connections.\n\n- create `lib/prisma.ts` file and add the following code\n\n```ts\nimport { PrismaClient } from \"@prisma/client\";\n\nconst prismaClientSingleton = () =\u003e {\n\treturn new PrismaClient({\n\t\tdatasources: { db: { url: process.env.DATABASE_URL } },\n\t\t...(process.env.DEBUG === \"1\" \u0026\u0026 {\n\t\t\tlog: [\"query\", \"info\"],\n\t\t}),\n\t});\n};\n\ntype PrismaClientSingleton = ReturnType\u003ctypeof prismaClientSingleton\u003e;\n\nconst globalForPrisma = globalThis as unknown as {\n\tprisma: PrismaClientSingleton | undefined;\n};\n\nexport const prisma = globalForPrisma.prisma ?? prismaClientSingleton();\n\nif (process.env.NODE_ENV !== \"production\") globalForPrisma.prisma = prisma;\n```\n\n- This code creates a singleton instance of Prisma Client, which is then exported as the `prisma\n- we shold use the Prisma client anywhere in your Next.js 15 application\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farunkumar201%2Fnextjs-self-host-starter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farunkumar201%2Fnextjs-self-host-starter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farunkumar201%2Fnextjs-self-host-starter/lists"}