You are using an unsupported browser. Please update your browser to the latest version on or before July 31, 2020.
close
Home > Projects > Project Types > Updating your Node apps for Fastify 4
Updating your Node apps for Fastify 4
print icon

If you have a project you remixed from Hello Node, Blank Node, Hello SQLite, or Blank SQLite before they were updated to use Fastify 4, you will need to carry out a few steps to get your app working for this framework update.

1. Update to Node 14

Fastify 4 requires a minimum of Node 14, so with your project open, in your package.json, change Node 12 to 14:

 

 

Give Glitch a minute or so to carry out this update–keep your Logs open throughout the process to see its progress.

2. Update Fastify

In the package.json ADD PACKAGE dropdown, select the updated version of the Fastify package (it should be 4+).

 

 

Give Glitch a minute again to carry out the update.

3. Replace deprecated packages

A few packages have been deprecated and replaced for Fastify 4, so you'll need to remove and replace them manually in your package.json.

 

If your project includes these, remove them:

 

  • fastify-static
  • point-of-view
  • fastify-formbody

 

In the package dropdown, search for the replacements and add them to your project:

 

  • @fastify/static
  • @fastify/view
  • @fastify/formbody

 

 

4. Update your Fastify server syntax

In server.js, adjust your listen function to pass any parameters inside an object.

 

Change this:

 

fastify.listen(process.env.PORT, '0.0.0.0', function(err, address) {

 

To this:

 

fastify.listen({ port: process.env.PORT, host: "0.0.0.0" }, function (err, address) {

 

5. Update dependency references

In your server.js code, if you have references to the deprecated / replaced dependencies, update them:

 

  • fastify-formbody > @fastify/formbody
  • fastify-static > @fastify/static
  • point-of-view > @fastify/view

 

 

6. Add return statements

Depending on your functionality, you may find the project doesn't behave as expected unless you add return statements before calls to view.

 

For example, in a Hello Node remix, you should replace the following line:

 

reply.view("/src/pages/index.hbs", params);

 

With this extended version:

 

return reply.view("/src/pages/index.hbs", params);

 

If you're in any doubt, check out the updated versions of the original apps!

 

Got more questions? Check out our Community Forum!
Open 24/7, the forum is where Glitch makers help each other and show off all the rad apps that they have created. It's the friendliest community of coders on the Web!
Feedback
1 out of 1 found this helpful

scroll to top icon