A NestJS application that fetches JSON data from URLs and stores it in MongoDB. The application includes scheduled tasks for regular data ingestion and comprehensive test coverage.
- JSON data ingestion from any URL
- In-memory MongoDB for development
- Scheduled hourly data ingestion
- Comprehensive test coverage
- RESTful API for querying ingested data
- Node.js (v20.10.0 or higher)
- npm or yarn
- MongoDB (for production)
# Install dependencies
npm installThe application uses an in-memory MongoDB instance in development mode, which is automatically populated on startup.
# Start the development server
npm run start:devThe development server will:
- Start an in-memory MongoDB instance
- Initialize the database with sample data from the test's API S3 File
- Start the NestJS application
- Begin scheduled hourly data ingestion
For production, you'll need to set up a MongoDB instance and configure the connection:
# Set the MongoDB connection string
export MONGO_URI=mongodb://your-mongodb-uri
# Start the production server
npm run start:prodGET /
Query Parameters:
field=value- Exact match for numeric fieldsfield=min,max- Range query for numeric fieldsfield=text- Case-insensitive partial text match
Examples:
- Exact price match:
GET http://localhost:3000/?priceForNight=252
- Price range query:
GET http://localhost:3000/?priceForNight=100,120
- Combined price range and name search:
GET http://localhost:3000/?priceForNight=50,120&name=Rustic%20Cabin
- Multiple field search:
GET http://localhost:3000/?priceForNight=100,200&name=Cabin&location=Mountain
- Text search with spaces (URL encoded):
GET http://localhost:3000/?name=Cozy%20Mountain%20Retreat
Note: All text searches are case-insensitive and support partial matches.
The application includes a scheduled task that runs every hour to:
- Fetch JSON data from configured URLs
- Validate the data format
- Store the data in MongoDB
The application includes comprehensive test coverage for all modules and services:
# Run unit tests
npm run testTest coverage includes:
- JsonFetchService - Testing URL fetching and error handling
- IngestionService - Testing data ingestion and validation
- TasksService - Testing scheduled tasks
- AppStatusController - Testing API endpoints
In development mode (NODE_ENV=development):
- Uses in-memory MongoDB
- Automatically populated on startup
- No need for external MongoDB instance
- Scheduled tasks run every hour