Local Environment
Prerequisites
Before setting up the testing-api locally, ensure you have the following tools installed:
- Node.js: Version 18.x or higher is recommended.
- Package Manager:
npm(comes with Node.js) oryarn. - Git: For version control and cloning the repository.
- Docker (Optional): Required if you intend to run the API within a containerized environment or use external services like databases locally.
Installation
Follow these steps to clone the repository and install the necessary dependencies:
-
Clone the repository:
git clone https://github.com/UditAkhourii/testing-api.git cd testing-api -
Install dependencies: Using npm:
npm installUsing yarn:
yarn install
Configuration
The application uses environment variables to manage configuration across different environments.
-
Create an environment file: Copy the provided
.env.exampleto a new file named.env.cp .env.example .env -
Configure variables: Open the
.envfile and update the values to match your local setup. Key configurations typically include:
| Variable | Description | Default Value |
| :--- | :--- | :--- |
| PORT | The port the API server will listen on. | 3000 |
| API_KEY | Authentication key for Supervised AI platform integration. | your_secret_key |
| LOG_LEVEL | Level of logging detail (debug, info, warn, error). | info |
Running the Development Server
Once the dependencies are installed and the environment variables are configured, start the local development server:
# Using npm
npm run dev
# Using yarn
yarn dev
The server should now be running at http://localhost:3000. You can verify the setup by sending a GET request to the health check endpoint:
curl http://localhost:3000/health
Running Tests
As this is a testing API structure, validating the environment through the built-in test suite is highly recommended:
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
Docker Setup (Alternative)
To ensure consistency with the production environment, you can run the API using Docker:
-
Build the image:
docker build -t testing-api . -
Run the container:
docker run -p 3000:3000 --env-file .env testing-api