From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Built-in pipes (ParseArrayPipe)

Built-in pipes (ParseArrayPipe)

In NestJS, the parse array pipe is a built-in pipe that converts string values from request parameters like query strings or body parameters into arrays. It can be useful when your API endpoints need multiple values for a parameter. The working of parse array pipe is very simple. By default, NestJS treats incoming request parameter values as strings only. So when you apply the parse array pipe on decorators like query or body, it will simply convert the string value into an array. Let's check an example. We already have the get decorator and a method defined in the controller. Let me give the query decorator and inside the argument, I'll give the query parameter as num and the parse array pipe. We'll store the num value in the property of type number array and we return the value. Now in the postman, I'll define the route and the query parameter. And here we will pass a series of number values separated by comma. And when we make the request, we get an array with string values. Now…

Contents