{"id":11382,"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.","status":"active","version":"2.0.4","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install nest-csv-parser","lang":"bash","label":"npm"},{"cmd":"yarn add nest-csv-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add nest-csv-parser","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core parsing engine, nest-csv-parser is a wrapper around it.","package":"csv-parser","optional":false},{"reason":"Peer dependency for NestJS module functionality and decorators.","package":"@nestjs/common","optional":false},{"reason":"Peer dependency for core NestJS functionalities.","package":"@nestjs/core","optional":false}],"imports":[{"note":"Required for `imports` array in your NestJS root or feature module to make the parser available.","wrong":"import CsvModule from 'nest-csv-parser'","symbol":"CsvModule","correct":"import { CsvModule } from 'nest-csv-parser'"},{"note":"This injectable service is used to perform the actual CSV parsing. Inject it into your NestJS services or controllers.","wrong":"const { CsvParser } = require('nest-csv-parser')","symbol":"CsvParser","correct":"import { CsvParser } from 'nest-csv-parser'"},{"note":"While used in examples, `Injectable` is a core NestJS decorator and not exported by `nest-csv-parser` itself.","wrong":"import { Injectable } from 'nest-csv-parser'","symbol":"Injectable","correct":"import { Injectable } from '@nestjs/common'"}],"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."},"warnings":[{"fix":"Ensure your CSV header names (case-sensitive) directly correspond to the property names in your TypeScript entity class, or preprocess the CSV stream to rename headers.","message":"The `csv-parser` library (which `nest-csv-parser` wraps) expects CSV headers to exactly match the property names of your TypeScript `Entity` class. Mismatches will result in `undefined` values for those properties.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Pass an explicit `csvConfig` object to the `parse` method, for example: `csvParser.parse(stream, Entity, null, null, { separator: ',', strict: false })`.","message":"By default, `nest-csv-parser` configures the underlying `csv-parser` with `{ strict: true, separator: ';' }`. If your CSV uses a different separator (e.g., comma `,`) or has inconsistent row lengths, you must override `csvConfig` in the `parse` method.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always use `await` when calling `this.csvParser.parse(...)` within an `async` function.","message":"The `parse` method returns a `Promise<Entity[]>`. It's crucial to `await` this promise, especially when dealing with potentially large files, to ensure all data is processed before attempting to use the results. Forgetting `await` will result in a promise object instead of the parsed data.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'2.0.4':60 'act':30 'activ':73 'allow':96 'appear':72 'applic':28,89 'around':35 'cadenc':65 'configur':122 'consum':99 'content':133 'control':112 'count':115 'csv':2,6,22,39,100,120 'csv-parser':38,119 'current':56 'data':101 'depend':94 'design':12 'develop':97 'differenti':83 'direct':106 'document':80 'effici':128 'entir':132 'entiti':109 'explicit':68 'expos':42 'file':23,127 'framework':16 'function':44 'given':75 'handl':124 'histori':78 'idiomat':49 'import':92 'inject':53,95 'integr':86 'isn':66 'javascript':136 'larg':126 'librari':41 'lightweight':33 'line':114 'load':130 'maintain':74 'map':104 'memori':135 'modul':11,91 'nest':5 'nest-csv-pars':4 'nestj':1,15,48,88 'nestjs-idiomat':47 'offset':116 'option':111 'pars':21 'parser':3,7,40,121 'popular':37 'primari':82 'process':19 'project':71 'releas':64 'seamless':85 'server':26 'server-sid':25 'servic':54 'side':27 'simplifi':17 'stabl':57 'state':69 'stream':102,125 'strict':63 'typescript':108 'under':118 'use':90 'util':10 'version':58,77 'way':50 'within':24 'without':129 'wrapper':34","created_at":"2026-04-19T13:37:41.801414+00:00","updated_at":"2026-04-19T13:37:41.801414+00:00","problems":[{"fix":"Add `CsvModule` to the `imports` array of the NestJS module where you are using `CsvParser`. For example: `@Module({ imports: [CsvModule], providers: [...] })`.","cause":"The `CsvModule` has not been correctly imported into the `imports` array of the module where `CsvParser` is being injected, or the module providing `CsvModule` is not imported into the current module.","error":"Nest can't resolve dependencies of the CsvParser (?). Please make sure that the argument at index [0] is available in the CsvModule context."},{"fix":"Ensure `CsvParser` is correctly injected via the constructor (`private readonly csvParser: CsvParser`), and that `import { CsvParser } from 'nest-csv-parser'` is present at the top of the file.","cause":"This error typically occurs if TypeScript cannot infer the type of `csvParser` or if an older version of the package is used that might have a different API. More commonly, it means `CsvParser` was not properly injected or imported.","error":"Property 'parse' does not exist on type 'CsvParser'."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/nest-csv-parser","openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework","serialization","data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}