Environment Setup
This guide provides step-by-step instructions for setting up the development environment for the Digibit ERP system.
Prerequisites
Before you begin, ensure you have the following installed on your system:
Required Software
- Node.js (v18 or higher)
- npm (v8 or higher) or yarn
- Angular CLI (v18 or higher)
- Git
- IDE/Text Editor (VS Code recommended)
Optional Software
- Docker (for containerized development)
- PostgreSQL Client (for direct database access)
- Supabase CLI (for local Supabase development)
Installation Steps
1. Clone the Repository
git clone <repository-url>
cd digibit
2. Install Dependencies
npm install
This will install all the necessary packages listed in package.json.
3. Environment Configuration
Create a .env file in the root directory with the following variables:
SUPABASE_URL=your_supabase_project_url
SUPABASE_ANON_KEY=your_supabase_anon_key
BACKEND_URL=your_backend_api_url
Alternatively, you can configure these in the environment.ts file located at src/environments/environment.ts.
4. IDE Configuration
VS Code Settings
Install the following extensions for optimal development experience: - Angular Language Service - TypeScript Importer - Prettier - Code formatter - ESLint - GitLens - Path Intellisense
Create a .vscode/settings.json file with recommended settings:
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"typescript.preferences.includePackageJsonAutoImports": "auto",
"files.exclude": {
"**/node_modules": true
}
}
Development Server
Starting the Development Server
ng serve
The application will be accessible at http://localhost:4200/.
Development Server Options
ng serve --port 4201: Use a different portng serve --open: Automatically open the browserng serve --host 0.0.0.0: Listen on all interfacesng serve --ssl: Serve using HTTPS
Building the Application
Development Build
ng build
Production Build
ng build --configuration production
Watch Mode
ng build --watch
Database Setup
Supabase Configuration
The application uses Supabase as the backend service. To set up your local development environment:
- Create a Supabase account at supabase.io
- Create a new project
- Note your Project URL and Anonymous Key
- Configure the database schema according to the project documentation
Local Database (Optional)
If you prefer to use a local PostgreSQL instance:
- Install PostgreSQL locally
- Create a database for the project
- Update connection settings in your environment configuration
Testing Environment
Running Tests
Execute unit tests:
ng test
Run tests once (without watch mode):
ng test --watch=false
Run tests with coverage:
ng test --code-coverage
Run end-to-end tests:
ng e2e
Linting
Check code for linting errors:
ng lint
Fix auto-fixable linting errors:
ng lint --fix
Docker Setup (Optional)
Using Docker for Development
If you prefer to use Docker for development:
- Ensure Docker and Docker Compose are installed
- Create a
docker-compose.ymlfile:
version: '3.8'
services:
app:
build: .
ports:
- "4200:4200"
volumes:
- .:/app
- /app/node_modules
environment:
- NODE_ENV=development
- Build and run the container:
docker-compose up --build
Troubleshooting
Common Issues
Module not found errors
Run npm install to ensure all dependencies are installed.
Port already in use
Use ng serve --port 4201 to use a different port.
Build errors
Clear cache with ng cache clean and rebuild.
SSL Certificate Errors
Set NODE_TLS_REJECT_UNAUTHORIZED=0 in your environment (only for development).
Verifying Installation
To verify your environment is set up correctly:
- Run
node --versionto check Node.js version - Run
npm --versionto check npm version - Run
ng versionto check Angular CLI version - Run
ng serveand navigate tohttp://localhost:4200/to confirm the app loads
Recommended Development Workflow
Daily Development Routine
- Pull latest changes:
git pull origin main - Install dependencies if needed:
npm install - Start development server:
ng serve - Create a new branch for your work:
git checkout -b feature/my-feature - Make your changes
- Run tests:
ng test --watch=false - Commit your changes with descriptive messages
- Push your branch and create a pull request
Useful npm Scripts
Check package.json for available scripts:
- npm start: Alias for ng serve
- npm run build: Build the application
- npm test: Run unit tests
- npm run lint: Run linting
- npm run e2e: Run end-to-end tests