Request object
To access the client request details, you can ask Nest.js to inject the request object into a handler using the @Req()
decorator. Nest.js uses express request objects.
For example,
import
{
Controller
,
Get
,
Req
}
from
'@nestjs/common'
;
import
{
Request
}
from
'express'
;
@
Controller
(
'entries'
)
export
class
EntryController
{
@
Get
()
index
(
@
Req
()
req
:Request
)
:
Entry
[]
{
const
entries
:Entry
[]
=
this
.
entriesService
.
findAll
();
return
entries
;
}
The typings for the Request
object come from express. Add the @types/express
package to your devDependencies
in package.json
to use these typings.