fastify 后台
Fast and low overhead web framework, for Node.js
快速,低开销的Web框架,用于Node.js
Fastify version 1 was released on March 7th. This post will show you how to get it set up, and we’ll discuss some of the incredible features Fastify has to offer. No configuration is necessary — Fastify’s code base will run on Node versions 6.x, 8.x, and 9.x.
Fastify版本1已于3月7日发布 。 这篇文章将向您展示如何进行设置,并且我们将讨论Fastify提供的一些令人难以置信的功能。 无需配置-Fastify的代码库将在Node版本6.x,8.x和9.x上运行。
准备? (Ready?)
Start with npm i fastify
and then:
从npm i fastify
开始,然后:
const fastify = require('fastify')()
fastify.get('/', (request, reply) => { reply.send({ hello: 'world' })})
fastify.listen(3000, err => { if (err) { fastify.log.error(err) process.exit(1) } fastify.log.info( `server listening on ${fastify.server.address().port}` )})
Now launch your server with: node server
现在使用以下命令启动服务器: node server
? That’s it! You’ve got your first Fastify server up and running.
? 而已! 您已经启动并运行了第一台Fastify服务器。
这里发生了什么? (What’s going on here?)
const fastify = require('fastify')()
Line 1 is importing the Fastify framework into the JavaScript project and instantiating it. Your server instance is now stored in the fastify
variable. You can pass additional options to this line like so:
第1行将Fastify框架导入JavaScript项目并实例化。 您的服务器实例现在存储在fastify
变量中。 您可以像这样将其他选项传递