
Research
/Security News
737 Chrome VPN Extensions Linked to Brand Impersonation and Browser Traffic Redirection
The campaign amassed more than 75,000 installs by targeting Russian-speaking users seeking access to blocked services.
nest-ndjson-req-stream
Advanced tools
Accept and automatically parse NDJSON stream requests in NestJS with Express!
A lightweight library that enables NestJS applications to accept and process streaming NDJSON (Newline Delimited JSON) requests with Express. Perfect for handling large datasets, real-time data feeds, and streaming APIs where each line contains a valid JSON object.
npm install nest-ndjson-req-stream
import { Controller, Post } from '@nestjs/common';
import { NdJsonStreamReq, NdJsonStreamRequest } from 'nest-ndjson-req-stream';
interface DataItem {
id: number;
name: string;
value: number;
}
@Controller('stream')
export class StreamController {
@Post('process')
async processStream(
@NdJsonStreamReq<DataItem>() request: NdJsonStreamRequest<DataItem>
) {
const results: DataItem[] = [];
// Process each item from the stream
for await (const item of request.body) {
// Process your data here
console.log('Received:', item);
results.push(item);
}
return {
message: 'Stream processed successfully',
itemCount: results.length,
};
}
}
If the stream contains a malformed JSON line, request.body will throw at that point in the for await loop. Wrap your controller logic to return a 400:
@Post('process')
async processStream(
@NdJsonStreamReq<DataItem>() request: NdJsonStreamRequest<DataItem>
) {
try {
for await (const item of request.body) {
console.log('Received:', item);
}
} catch (error) {
throw new BadRequestException(`Invalid NDJSON: ${error.message}`);
}
}
The error object carries .line (the offending text), .itemNumber (1-based position in the stream), and .cause (the original SyntaxError).
Use TypeScript generics for type-safe stream processing:
interface User {
id: string;
email: string;
profile: {
name: string;
age: number;
};
}
@Post('users')
async importUsers(
@NdJsonStreamReq() request: NdJsonStreamRequest<User>
) {
for await (const user of request.body) {
// TypeScript knows that user is of type User
console.log(user.email); // ✅ Type safe
console.log(user.profile.name); // ✅ Type safe
}
}
@NdJsonStreamReq(options?: NdJsonStreamOptions)Parameter decorator for handling NDJSON streaming requests.
batchSize?: number - The batch size for processing streamed objects (default: 25)NdJsonStreamRequest<T>Extended Express Request interface with AsyncGenerator type body:
body: AsyncGenerator<T> - AsyncGenerator that yields parsed NDJSON objectsbatchSize: number - The configured batch size for processing# Run unit tests
npm run test
# Run tests with coverage
npm run test:cov
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)This project is MIT licensed.
FAQs
Accept and automatically parse NDJSON request streams.
We found that nest-ndjson-req-stream demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
The campaign amassed more than 75,000 installs by targeting Russian-speaking users seeking access to blocked services.

Company News
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.

Security News
The supply chain control that delays freshly published gems now covers lockfile generation and gem vendoring in Ruby projects.