This is a URL shortening service built with Node.js, TypeScript, and Express. It includes features for encoding, decoding, and retrieving statistics for URLs. The service uses caching for performance optimization and includes unit and integration tests for reliability.
-
Install dependencies:
yarn install
-
Set up environment variables: Create a
.env
file in the root directory with the following variables:PORT=3000 BASE_URL=http://localhost:3000 CACHE_TTL=3600
-
Start the server:
yarn dev
-
API Endpoints:
POST /encode
: Encodes a URL to a shortened URL.POST /decode
: Decodes a shortened URL to its original URL.GET /statistic/{url_path}
: Returns basic statistics for a short URL path.
-
Run all tests:
yarn test
-
Run tests in watch mode:
yarn test:watch
-
Run tests with coverage:
yarn test:coverage
src/
: Contains the source code.controllers/
: Express controllers.dtos/
: Data transfer objects.models/
: Mongoose models.repositories/
: Database repositories.services/
: Business logic services.utils/
: Utility functions and classes.
tests/
: Contains test files.unit/
: Unit tests.integration/
: Integration tests.
Feel free to open issues or submit pull requests for iomplmprovements and bug fixes.
This project is licensed under the MIT License.