{"library":"nest-csv-parser","title":"NestJS CSV Parser","description":"nest-csv-parser is a utility module designed for the NestJS framework, simplifying the process of parsing CSV files within server-side applications. It acts as a lightweight wrapper around the popular `csv-parser` library, exposing its functionality in a NestJS-idiomatic way through an injectable service. The current stable version is 2.0.4. While a strict release cadence isn't explicitly stated, the project appears actively maintained given its version history and documentation. Its primary differentiator is seamless integration into NestJS applications using `@Module` imports and dependency injection, allowing developers to consume CSV data streams and map them directly to TypeScript entities with optional control over line counts, offsets, and underlying `csv-parser` configurations. It handles streaming large files efficiently without loading the entire content into memory.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install nest-csv-parser"],"cli":null},"imports":["import { CsvModule } from 'nest-csv-parser'","import { CsvParser } from 'nest-csv-parser'","import { Injectable } from '@nestjs/common'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { Module, Injectable } from '@nestjs/common';\nimport { CsvModule, CsvParser } from 'nest-csv-parser';\nimport * as fs from 'fs';\n\n// 1. Define your entity structure matching CSV headers\nclass MyDataEntity {\n  id: number;\n  name: string;\n  value: string;\n}\n\n@Injectable()\nexport class MyCsvService {\n  constructor(\n    private readonly csvParser: CsvParser\n  ) {}\n\n  async parseMyCsvFile(): Promise<MyDataEntity[]> {\n    // Create a dummy CSV file for demonstration\n    const csvContent = 'id,name,value\\n1,Alice,Alpha\\n2,Bob,Beta\\n3,Charlie,Gamma';\n    const filePath = './temp.csv';\n    fs.writeFileSync(filePath, csvContent);\n\n    // Create a readable stream from the file\n    const stream = fs.createReadStream(filePath);\n\n    try {\n      // Parse the stream into an array of MyDataEntity objects\n      const entities: MyDataEntity[] = await this.csvParser.parse(stream, MyDataEntity);\n      console.log('Parsed Entities:', entities);\n      return entities;\n    } finally {\n      // Clean up the dummy file\n      fs.unlinkSync(filePath);\n    }\n  }\n}\n\n@Module({\n  imports: [CsvModule],\n  providers: [MyCsvService],\n  exports: [MyCsvService]\n})\nexport class MyCsvParsingModule {}\n\n// Example of how to use it (e.g., in your main.ts or another module)\nasync function bootstrap() {\n  // In a real NestJS app, this would be handled by the framework\n  // For quickstart, we'll manually instantiate\n  const moduleRef = await import('@nestjs/core').then(m => m.NestFactory.createApplicationContext(MyCsvParsingModule));\n  const myCsvService = moduleRef.get(MyCsvService);\n  await myCsvService.parseMyCsvFile();\n  await moduleRef.close();\n}\n\nbootstrap();","lang":"typescript","description":"This quickstart demonstrates how to set up `CsvModule` in a NestJS application, define a TypeScript entity to map CSV data, and use `CsvParser` to read and parse a CSV file stream into an array of typed objects. It includes creating a temporary CSV file for demonstration.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}