Fastify上传文件
@nestjs/common包中的UploadedFile只能用于express的适配器,而用来fastify的,那么需要从fastify对应的包导出。
Fastify 托管静态文件、图片
app.useStaticAssets({
root: join(__dirname, '..', 'uploads'),
prefix: '/public',
});
注意点:public
、public/
都会报错。
模型定义与参数验证合并
- 参数过滤
- 分页
- Migrating to Express 5
- node.js – Express V5: Is there any way to modify `req.query`? – Stack Overflow
In Express.js version 5 and later, req.query
is an object that holds the query parameters parsed from the URL’s query string. These query parameters are essentially key-value pairs that appear after a question mark (?) in the URL, separated by ampersands (&) if there are multiple parameters.
Here’s a breakdown of how req.query
works in Express 5:
- Key-Value Pairs: The
req.query
object contains properties corresponding to each query parameter, where the property name is the parameter’s key and the value is its associated value from the URL. - Example: For a URL like
https://example.com/user?name=Theodore&isAuthor=true
,req.query
would be{ name: "Theodore", isAuthor: true }
. - Accessing Values: You can access the value of a specific query parameter using dot notation, e.g.,
req.query.name
would give you"Theodore"
.
Important considerations for Express v5
- Immutable Getter: In Express v5,
req.query
is now a getter that reflects the contents ofreq.url
. This means you cannot directly modifyreq.query
like you might have in earlier versions. If you need to alter the query for transparent processing, you’ll need to modifyreq.url
itself. - Validation and Transformation: If you need to validate or transform query parameters, you can read their values from
req.query
and then assign them to a different property on thereq
object (e.g.,req.validatedQuery
).
In essence, req.query
remains the primary way to access URL query parameters in Express 5, but its behavior regarding modification has changed. You can still easily read and utilize the parsed query string data, but direct manipulation of req.query
is no longer supported.