My First REST API » Fastify App's Scaffold

My First REST API » Fastify App's Scaffold


Fastify App's Scaffold

Create a new index.js file and use the following scaffold to kick off a new ForrestJS App:

// Import dependencies, mostly services that wrap famous Open Source libraries:
const forrest = require('@forrestjs/core');
const fastify = require('@forrestjs/service-fastify');
const fastifyHealthz = require('@forrestjs/service-fastify-healthz');

forrest
  .run({
    // It shows boot trace in the console
    // (very useful while developing)
    trace: 'compact',

    // You can set any kind of settings for your app
    // Services and Features will be able to read from this object via APIs
    settings: {},

    // Services provide infrastructure to your business value
    services: [fastify, fastifyHealthz],

    // Features implement your business value
    features: [],
  })
  .catch(console.error);

Once ready, you can run it with:

npx nodemon index

Once the app is running, you should test it at the following urls:


💻 Live on CodeSandbox:
https://codesandbox.io/s/fastify-app-scaffold-oc3q9?file=/src/index.js

NOTE: CodeSandbox requires the following settings in order to setup the proper ports binding.

settings: {
  fastify: {
    meta: null;
  }
}

But if you run this tutorial on your local machine, this may cause troubles.


results matching ""

    No results matching ""