- Prerequisites
- Setup and Usage Instructions
- Available Commands
- Running Scripts
- Troubleshooting
- Best Practices
- Extending the Application
- External Resources
1.0.0
June 2026
- Node.js: Version 16 or higher
- MongoDB: Version 4.4 or higher
- Operating System: Windows, macOS, or Linux
- Snowflake Account: Active account with metadata access permissions
npm install- Open the project in your IDE (VSCode recommended)
- Install dependencies:
npm install
- Configure environment variables (see Configuration section)
- Ensure MongoDB is running locally or update connection string
- Ensure Snowflake credentials are valid
Update the MongoDB connection in src/config/constants.config.ts:
MONGODB: {
CONNECTION_URL: 'mongodb://127.0.0.1:27017/test',
}For production, use environment variables instead of hardcoded values.
SECURITY WARNING: The current implementation has hardcoded credentials in src/config/constants.config.ts. Before deploying or committing:
- Move credentials to environment variables
- Update
config/env.jsonwith placeholder values - Load from environment in
config/env.js - Reference from
CONSTANTS.DATA.SNOWFLAKEusing env vars
Current configuration structure:
SNOWFLAKE: {
ACCESS_URL: 'https://your-account.snowflakecomputing.com',
USERNAME: 'your-username',
PASSWORD: 'your-password',
ACCOUNT: 'YOUR_ACCOUNT_ID',
DATABASE: 'YOUR_DATABASE',
ROLE: 'YOUR_ROLE',
TABLE: 'YOUR_SCHEMA',
}Server settings in src/config/constants.config.ts:
SERVER: {
PORT: '8080',
EXPRESS_LIMIT: '5mb',
}npm run devnpm run startThis will:
- Compile TypeScript to JavaScript
- Start the server on port 8080 (or configured port)
- Connect to MongoDB
- Connect to Snowflake
- Initialize Swagger UI at
/api-docs
npm run killOnce the server is running, access the interactive API documentation:
http://localhost:8080/api-docs
POST /api/metadata/integration/sync
Fetches all table metadata from Snowflake and syncs to MongoDB.
Response:
{
"status": "success"
}What it does:
- Clears existing metadata in MongoDB
- Queries Snowflake for all tables in the configured schema
- Fetches column information for each table
- Stores the complete metadata in MongoDB
GET /api/metadata/tables?page=1&limit=10
Retrieves table metadata from MongoDB with pagination.
Query Parameters:
page(required): Page number (default: 1)limit(required): Items per page (default: 10)
Response:
{
"data": [
{
"_id": "...",
"created_on": "2021-11-10T05:04:44.572Z",
"name": "TABLE_NAME",
"database_name": "SNOWFLAKE_SAMPLE_DATA",
"schema_name": "SCHEMA_NAME",
"kind": "TABLE",
"columns": [
{
"name": "COLUMN_NAME",
"type": "TEXT"
}
],
"rows": 1000,
"bytes": 50000
}
],
"page": 1,
"limit": 10,
"totalRecords": 24
}npm install
npm run devUse Swagger UI or curl:
curl -X POST http://localhost:8080/api/metadata/integration/synccurl http://localhost:8080/api/metadata/tables?page=1&limit=10npm run lintnpm run prettier-checknpm run prettier-fixsnowflake/
├── src/
│ ├── config/ # Configuration constants
│ ├── controllers/ # Express route controllers
│ ├── custom/ # Custom error classes
│ ├── helpers/ # Express helper utilities
│ ├── middlewares/ # Express middlewares (validation, logging, errors)
│ ├── models/ # Business logic models
│ ├── routes/ # API route definitions
│ │ └── public/ # Public routes (no auth)
│ ├── schemas/ # Mongoose schemas
│ ├── services/ # External service integrations
│ │ ├── logger.service.ts
│ │ ├── mongodb.service.ts
│ │ ├── snowflake.service.ts
│ │ └── swagger.service.ts
│ ├── utils/ # Utility functions
│ ├── validations/ # Joi validation schemas
│ └── app.ts # Express app entry point
├── config/ # Environment configuration
│ ├── env.js
│ └── env.json
└── dist/ # Compiled JavaScript output
The application uses a custom error handling system:
CustomErrorclass insrc/custom/error.custom.ts- Centralized error middleware in
src/middlewares/errors.middleware.ts - All errors return consistent JSON responses
Winston logger configured in src/services/logger.service.ts:
- All requests logged via
src/middlewares/logs.middleware.ts - Service initialization logs
- Error logs with stack traces
Before deploying to production:
- Remove hardcoded credentials from
src/config/constants.config.ts - Use environment variables for all sensitive data
- Enable authentication on API endpoints
- Use HTTPS instead of HTTP
- Configure CORS properly (currently set to
*) - Enable rate limiting to prevent abuse
- Validate all inputs (already implemented with Joi)
- Use MongoDB connection with authentication
- Set proper Snowflake role permissions (least privilege)
# Start development server with hot-reload
npm run dev
# Run linter
npm run lint
# Format code
npm run prettier-fix
# Check formatting
npm run prettier-check# Compile and start production server
npm run start
# Kill running node processes (Windows)
npm run killTo install all required dependencies for the project:
npm install- Ensure MongoDB is running locally (
mongod) - Verify the connection string in
src/config/constants.config.ts - Check for firewall blocks on port 27017
- Verify credentials and account URL
- Ensure the user has appropriate role and database access
- Check network connectivity to Snowflake endpoints
- Use
npm run killto stop existing processes - Or change the port in
src/config/constants.config.ts
- Security: Never commit sensitive credentials to the repository. Use environment variables.
- Validation: Always use Joi schemas to validate incoming request data.
- Logging: Use the structured Winston logger for all service-level operations.
- Error Handling: Utilize the
CustomErrorclass for consistent API responses.
- Define the route in
src/routes/public/ - Register the route in
src/routes/index.public.routes.ts - Implement the controller logic in
src/controllers/
- Create a new service file in
src/services/ - Implement the integration or business logic
- Use the service in controllers or models
- Or Assayag - Initial work - orassayag
- Or Assayag orassayag@gmail.com
- GitHub: https://github.com/orassayag
- StackOverflow: https://stackoverflow.com/users/4442606/or-assayag?tab=profile
- LinkedIn: https://linkedin.com/in/orassayag