https://github.com/adityasharmahub/csv-parser-api
CSV to JSON Parser API using Node.js and Express.js
https://github.com/adityasharmahub/csv-parser-api
csv csv-parser expressjs json json-parser nodejs
Last synced: about 2 months ago
JSON representation
CSV to JSON Parser API using Node.js and Express.js
- Host: GitHub
- URL: https://github.com/adityasharmahub/csv-parser-api
- Owner: AdityaSharmaHub
- Created: 2025-07-26T09:43:34.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-07-26T11:11:28.000Z (11 months ago)
- Last Synced: 2025-08-04T22:50:07.790Z (11 months ago)
- Topics: csv, csv-parser, expressjs, json, json-parser, nodejs
- Language: JavaScript
- Homepage: https://github.com/AdityaSharmaHub/csv-parser-api
- Size: 13.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CSV to JSON Parser API
A Node.js API that converts CSV files to JSON and uploads data to PostgreSQL database with age distribution analysis.
## Features
- Custom CSV parser (no external libraries)
- Handles nested properties with dot notation (e.g., `name.firstName`, `address.city`)
- PostgreSQL database integration
- Age distribution analysis
- RESTful API endpoint
## Setup
1. **Install dependencies:**
```bash
npm install
```
2. **Configure environment variables:**
```bash
cp env.example .env
```
Edit `.env` with your database credentials and CSV file path.
3. **Create PostgreSQL database table:**
```sql
CREATE TABLE public.users (
"name" varchar NOT NULL,
age int4 NOT NULL,
address jsonb NULL,
additional_info jsonb NULL,
id serial4 NOT NULL
);
```
4. **Start the server:**
```bash
node index.js
```
## API Endpoints
### GET /upload
Processes the CSV file and uploads data to the database.
**Response:**
```json
{
"success": true,
"message": "Upload complete and age distribution printed",
"usersProcessed": 10
}
```
## CSV Format
The CSV file should have headers with dot notation for nested properties:
```
name.firstName,name.lastName,age,address.line1,address.city,gender
Rohit,Prasad,35,A-563 Rakshak Society,Pune,male
```
## Environment Variables
- `PORT` - Server port (default: 3000)
- `CSV_FILE_PATH` - Path to CSV file (default: ./uploads/users.csv)
- `PGHOST` - PostgreSQL host
- `PGUSER` - PostgreSQL username
- `PGPASSWORD` - PostgreSQL password
- `PGDATABASE` - PostgreSQL database name
- `PGPORT` - PostgreSQL port (default: 5432)