In the world of Node.js, Express has been a trusted companion for developers. However, as applications scale and require more performance, Fastify, a high-performance, low-overhead web framework for Node.js, has emerged as an excellent alternative. This blog post will guide you through migrating an existing Express application to Fastify, step by step.
Our Express application is a simple property management API with the following features:
Here is the entire code for our Express application:
You’ll need NodeJS installed in your system, 16 and onwards should work.
$ npm install express express-async-handler [email protected] winston lodash-id
$ npm install -D standardjs supertest tap
package.json
:{
"name": "fastify-express-migration-poc",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"lint": "npx standard",
"lint:fix": "npx standard --fix",
"test": "NODE_ENV=test tap test/**/*.test.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.18.2",
"express-async-handler": "^1.2.0",
"lodash-id": "^0.14.1",
"lowdb": "^1.0.0",
"winston": "^3.8.2"
},
"devDependencies": {
"standardjs": "^1.0.0-alpha",
"supertest": "^6.3.3",
"tap": "^16.3.4"
}
}
index.js