Loading gists…
A Text snippet, saved for reference.
| 1 | Final Backend setup command |
| 2 | # 1. Init project |
| 3 | npm init -y |
| 4 | |
| 5 | # 2. Install TypeScript + dev tools |
| 6 | npm install --save-dev typescript ts-node nodemon @types/node |
| 7 | |
| 8 | # 3. Initialize TS config |
| 9 | npx tsc --init |
| 10 | |
| 11 | # 4. Install Express + types |
| 12 | npm install express |
| 13 | npm install --save-dev @types/express |
| 14 | |
| 15 | # 5. Install Prisma + setup client |
| 16 | npm install prisma --save-dev |
| 17 | npm install @prisma/client |
| 18 | npx prisma init |
| 19 | |
| 20 | # 6. Install Auth & utility packages |
| 21 | npm install bcrypt jsonwebtoken dotenv error-cure zod |
| 22 | npm install --save-dev @types/bcrypt @types/jsonwebtoken |
| 23 | |
| 24 | # 7. Run dev server |
| 25 | npm run dev |
| 26 | |
| 27 | # 8. Compile TS (for production) |
| 28 | npm run build |
| 29 | |
| 30 | # 9. Start compiled JS |
| 31 | npm start |
| 32 | |
| 33 | # 10. Prisma migrate & generate |
| 34 | npx prisma migrate dev --name init |
| 35 | npx prisma generate |
| 36 | |
| 37 | |
| 38 | .env |
| 39 | # Database Configuration |
| 40 | # Replace with your actual PostgreSQL connection string |
| 41 | DATABASE_URL="postgresql://postgres:nishandhakal@localhost:5432/auth_db?schema=public" |
| 42 | |
| 43 | # JWT Configuration |
| 44 | JWT_SECRET="your-super-secret-jwt-key-change-this-in-production" |
| 45 | JWT_EXPIRES_IN="7d" |
| 46 | |
| 47 | # Server Configuration |
| 48 | PORT=3000 |
| 49 | NODE_ENV="development" |
| 50 | |
| 51 | |
| 52 | ----------------------------------------------------------------------------------------------------- |
| 53 | tsconfig file |
| 54 | { |
| 55 | // Visit https://aka.ms/tsconfig to read more about this file |
| 56 | "compilerOptions": { |
| 57 | // File Layout |
| 58 | // "rootDir": "./src", |
| 59 | // "outDir": "./dist", |
| 60 | // Environment Settings |
| 61 | // See also https://aka.ms/tsconfig/module |
| 62 | "module": "ESNext", |
| 63 | "moduleResolution": "bundler", |
| 64 | "allowImportingTsExtensions": true, |
| 65 | "noEmit": true, |
| 66 | "target": "esnext", |
| 67 | "types": [ |
| 68 | "node" |
| 69 | ], |
| 70 | "esModuleInterop": true, |
| 71 | "allowSyntheticDefaultImports": true, |
| 72 | // For nodejs: |
| 73 | // "lib": ["esnext"], |
| 74 | // "types": ["node"], |
| 75 | // and npm install -D @types/node |
| 76 | // Other Outputs |
| 77 | "sourceMap": true, |
| 78 | "declaration": true, |
| 79 | "declarationMap": true, |
| 80 | // Stricter Typechecking Options |
| 81 | "noUncheckedIndexedAccess": true, |
| 82 | "exactOptionalPropertyTypes": true, |
| 83 | // Style Options |
| 84 | // "noImplicitReturns": true, |
| 85 | // "noImplicitOverride": true, |
| 86 | // "noUnusedLocals": true, |
| 87 | // "noUnusedParameters": true, |
| 88 | // "noFallthroughCasesInSwitch": true, |
| 89 | // "noPropertyAccessFromIndexSignature": true, |
| 90 | // Recommended Options |
| 91 | "strict": true, |
| 92 | "jsx": "react-jsx", |
| 93 | "verbatimModuleSyntax": true, |
| 94 | "isolatedModules": true, |
| 95 | "noUncheckedSideEffectImports": true, |
| 96 | "moduleDetection": "force", |
| 97 | "skipLibCheck": true, |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | |
| 102 | |
| 103 | ---------------------------------------------------------------------------------------- |
| 104 | package json |
| 105 | |
| 106 | { |
| 107 | "name": "backend", |
| 108 | "version": "1.0.0", |
| 109 | "description": "", |
| 110 | "main": "index.js", |
| 111 | "scripts": { |
| 112 | "dev": "ts-node src/server.ts", |
| 113 | "test": "echo \"Error: no test specified\" && exit 1" |
| 114 | }, |
| 115 | "keywords": [], |
| 116 | "author": "", |
| 117 | "license": "ISC", |
| 118 | "type": "module", |
| 119 | "devDependencies": { |
| 120 | "@types/cors": "^2.8.19", |
| 121 | "@types/express": "^5.0.6", |
| 122 | "@types/node": "^25.0.6", |
| 123 | "prisma": "^7.2.0", |
| 124 | "ts-node": "^10.9.2", |
| 125 | "ts-node-dev": "^2.0.0", |
| 126 | "typescript": "^5.9.3" |
| 127 | }, |
| 128 | "dependencies": { |
| 129 | "@prisma/client": "^7.2.0", |
| 130 | "cors": "^2.8.5", |
| 131 | "dotenv": "^17.2.3", |
| 132 | "express": "^5.2.1" |
| 133 | } |
| 134 | } |
| 135 | -------------------------------------------------------------------------------------- |
| 136 | |
| 137 | also install nodemon for auto server restart when code changes |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 |