File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -53,17 +53,18 @@ ut.code(); Learnに準拠したサンプルプロジェクトです。
5353 $ mkdir backend
5454 $ cd backend
5555 $ npm init
56- $ npm install express cors
57- $ npm install -D typescript tsx @types/express @types/cors
56+ $ npm install express @prisma/client dotenv cors
57+ $ npm install -D typescript tsx @types/express prisma @types/cors
5858 $ npx tsc --init
5959 $ npx prisma init
6060 ```
6161
62621 . ` /frontend/.env ` を作成して、` VITE_API_ENDPOINT ` を` http://localhost:3000 ` に設定する
63+ 1 . ` /backend/package.json ` で` type ` フィールドを` module ` に設定する
63641 . ` /backend/.env ` で` WEB_ORIGIN ` を` http://localhost:5173 ` に設定し、` DATABASE_URL ` も設定する
65+ 1 . ` /backend/prisma.config.ts ` に` import "dotenv/config"; ` を追加して、` .env ` の内容が読み込まれるようにする
64661 . ` /backend/prisma/schema.prisma ` の内容をデータベースに反映させるために` npx prisma db push ` を実行する
65671 . ` /backend/tsconfig.json ` の` outDir ` オプションを` ./dist ` にしてトランスパイル結果が` /backend/dist ` に入るようにする
66- 1 . ` /backend/tsconfig.json ` の` declaration ` オプションと` declarationMap ` オプションを消し` allowJs ` オプションを` true ` にしてPrismaが生成したJavaScriptファイルをトランスパイル結果に含めるようにする
67681 . ` /backend/dist ` を` /backend/.gitignore ` に追加する
68691 . ` /backend/package.json ` を変更して次のコマンドが使えるようにする
6970 - ` npm run dev ` :` tsx ` を使ってトランスパイル前のTypeScriptを直接実行する(開発環境用)
Original file line number Diff line number Diff line change 11import express from "express" ;
22import cors from "cors" ;
3- import { PrismaClient } from "./generated/prisma/index .js" ;
3+ import { PrismaClient } from "./generated/prisma/client .js" ;
44
55const app = express ( ) ;
66const client = new PrismaClient ( ) ;
Original file line number Diff line number Diff line change 11{
22 "name" : " backend" ,
3+ "type" : " module" ,
34 "scripts" : {
4- "dev" : " tsx main.mts " ,
5+ "dev" : " tsx --env-file=.env main.ts " ,
56 "build" : " tsc" ,
6- "start" : " node dist/main.mjs "
7+ "start" : " node --env-file=.env dist/main.js "
78 },
89 "dependencies" : {
9- "@prisma/client" : " ^6.17.1 " ,
10+ "@prisma/client" : " ^6.18.0 " ,
1011 "cors" : " ^2.8.5" ,
12+ "dotenv" : " ^17.2.3" ,
1113 "express" : " ^5.1.0"
1214 },
1315 "devDependencies" : {
1416 "@types/cors" : " ^2.8.19" ,
1517 "@types/express" : " ^5.0.3" ,
16- "prisma" : " ^6.17.1 " ,
18+ "prisma" : " ^6.18.0 " ,
1719 "tsx" : " ^4.20.6" ,
1820 "typescript" : " ^5.9.3"
1921 }
Original file line number Diff line number Diff line change 1+ import "dotenv/config" ;
2+ import { defineConfig , env } from "prisma/config" ;
3+
4+ export default defineConfig ( {
5+ schema : "prisma/schema.prisma" ,
6+ migrations : {
7+ path : "prisma/migrations" ,
8+ } ,
9+ engine : "classic" ,
10+ datasource : {
11+ url : env ( "DATABASE_URL" ) ,
12+ } ,
13+ } ) ;
Original file line number Diff line number Diff line change 55// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
66
77generator client {
8- provider = " prisma-client-js "
8+ provider = " prisma-client "
99 output = " ../generated/prisma "
1010}
1111
Original file line number Diff line number Diff line change 1717
1818 // Other Outputs
1919 "sourceMap" : true ,
20- // "declaration": true,
21- // "declarationMap": true,
22- "allowJs" : true ,
20+ "declaration" : true ,
21+ "declarationMap" : true ,
2322
2423 // Stricter Typechecking Options
2524 "noUncheckedIndexedAccess" : true ,
You can’t perform that action at this time.
0 commit comments