A Node.js backend service built with Express and TypeScript that handles phone authentication and user profile management using Firebase.
- Node.js
- npm
- Firebase project with Phone Authentication enabled
- Firebase Admin SDK credentials
- Clone the repository and install dependencies:
git clone <repository-url>
cd backend
npm install
-
Configure Firebase Admin SDK:
- Go to Firebase Console: https://console.firebase.google.com
- Select your project
- Go to Project Settings > Service Accounts
- Click "Generate New Private Key" and save the JSON file
-
make a copy of
.env.sample
with name.env
file in the root directory and set missing variables
# Start development server with hot reload
npm run dev
# Build for production
npm run build
# Start production server
npm start
GET /health
GET /api/profile
Authorization: Bearer {firebase-id-token}
PUT /api/profile
Authorization: Bearer {firebase-id-token}
Content-Type: application/json
{
"name": "Per Gustafsson",
"email": "per@example.com"
}
- Start the development server:
npm run dev
-
The server will start on http://localhost:3000
-
Test the health check endpoint:
curl http://localhost:3000/health
- Build the project:
npm run build
-
The compiled JavaScript will be in the
dist
directory. -
Start the production server:
npm start
- Rate limiting is enabled (100 requests per 15 minutes per IP)
- All routes (except /health) require Firebase authentication
- CORS is configured to allow only the frontend origin
Main dependencies:
express
: Web frameworkfirebase-admin
: Firebase Admin SDKtypescript
: TypeScript supportcors
: CORS middlewaredotenv
: Environment variablesexpress-rate-limit
: Rate limiting
Dev dependencies:
ts-node
: TypeScript executionnodemon
: Development auto-reload@types/node
: Node.js type definitions@types/express
: Express type definitions@typescript-eslint/parser
: TypeScript ESLint parser@typescript-eslint/eslint-plugin
: TypeScript ESLint rulesjest
: Testing frameworksupertest
: Superagent like libraryprettier
: Code formatter