站長資訊網
        最全最豐富的資訊網站

        分享一個Nodejs web框架:Fastify

        本篇文章給大家分享一個Nodejs web框架:Fastify,簡單介紹一下Fastify支持的特性、Fastify支持的插件以及Fastify的使用方法,希望對大家有所幫助!

        分享一個Nodejs web框架:Fastify

        前端的web框架,大部分都是建立在node基礎上的。fastify 也不例外。

        前端web框架性能比對

        如果真的是這樣的話,那么是很樂意去嘗試fastfy的 ??

        Benchmarks

        Machine: EX41S-SSD, Intel Core i7, 4Ghz, 64GB RAM, 4C/8T, SSD.

        Method: : autocannon -c 100 -d 40 -p 10 localhost:3000 * 2, taking the second average

        Framework Version Router? Requests/sec
        Express 4.17.3 ? 14,200
        hapi 20.2.1 ? 42,284
        Restify 8.6.1 ? 50,363
        Koa 2.13.0 ? 54,272
        Fastify 4.0.0 ? 77,193
        http.Server 16.14.2 ? 74,513

        Fastify支持的特性

        • 高性能: 請見上表.
        • Extensible: 通過 hooks, plugins and decorators 來實現擴展性.
        • Schema based: 不強制使用 JSON Schema 驗證你的路由配置,及時配置了,編譯也是很快的.
        • Logging: 使用Pino來記錄日志,并把損耗降低。
        • Developer friendly: 對開發者友好,而且對性能、安全性也有考慮、設計.
        • TypeScript ready: 支持 TypeScript

        Fastify支持的 plugins

        截止到目前, 48個核心插件 、179個社區插件

        分享一個Nodejs web框架:Fastify

        那么,如何使用呢?

        初始化

        創建工程

        npm install --global fastify-cli fastify generate myproject

        初始化工程

        npm init -y fastify

        安裝依賴

        #npm  npm i fastify  #yarn  yarn add fastify

        hello-world

        同步返回

        // ESM import Fastify from 'fastify' //const fastify = Fastify({   //logger: true //}) // CommonJs const fastify = require('fastify')({   logger: true })  // Declare a route fastify.get('/', (request, reply) => {   reply.send({ hello: 'world' }) })  // Run the server! fastify.listen({ port: 3000 }, (err, address) => {   if (err) throw err   // Server is now listening on ${address} })

        異步返回

        // ESM import Fastify from 'fastify' const fastify = Fastify({   logger: true }) // CommonJs //const fastify = require('fastify')({   //logger: true //})  fastify.get('/', async (request, reply) => {   reply.type('application/json').code(200)   return { hello: 'world' } })  fastify.listen({ port: 3000 }, (err, address) => {   if (err) throw err   // Server is now listening on ${address} })

        plugin如何使用

        fastify.register(plugin, [options]),

        贊(0)
        分享到: 更多 (0)
        網站地圖   滬ICP備18035694號-2    滬公網安備31011702889846號
        主站蜘蛛池模板: 国产精品成人va在线观看| 99久久人妻无码精品系列蜜桃| 性欧洲精品videos| 国产L精品国产亚洲区久久 | 亚洲精品色午夜无码专区日韩| 丁香色婷婷国产精品视频| 91精品国产91久久久久福利| 亚洲国产精品无码专区| 久久综合精品国产一区二区三区 | 四虎精品8848ys一区二区| 国产亚洲精品自在久久| 久久久精品国产Sm最大网站| 亚洲综合一区二区精品导航| 97人妻无码一区二区精品免费| 人妻少妇精品中文字幕AV | 福利姬在线精品观看| 久久精品麻豆日日躁夜夜躁| 亚洲国产精品日韩| 亚洲?V无码乱码国产精品| 久久露脸国产精品| 免费视频精品一区二区| 精品久久久久久99人妻| 国产欧美精品专区一区二区| 国产av无码专区亚洲国产精品| 99久久精品免费国产大片| 青青草国产精品| 精品一区二区久久久久久久网站| 97久久久久人妻精品专区| 亚洲AV永久青草无码精品| 人妻少妇偷人精品无码| 精品日韩亚洲AV无码| 国产在线精品免费aaa片| 99热精品在线| 51午夜精品免费视频| 精品福利一区二区三| 日本欧美韩国日本精品| 中文字幕精品视频| 国产韩国精品一区二区三区| 国产精品人人做人人爽| 精品国产亚洲男女在线线电影 | 久久综合国产乱子伦精品免费|