Server
Integration & Deployment
Node:HTTP

Node HTTP

Node.js is the most popular JavaScript runtime environment, and feTS supports it fully as well with a few lines of code.

This recipe shows how to use feTS with Node.js’ built-in HTTP implementation.

Installation

npm i fets

Example

import { createServer } from 'node:http'
import { createRouter, Response } from 'fets'
 
const router = createRouter().route({
  method: 'GET',
  path: '/greetings',
  schemas: {
    responses: {
      200: {
        type: 'object',
        properties: {
          hello: { type: 'string' }
        }
      }
    }
  },
  handler: () => Response.json({ hello: 'world' })
})
 
createServer(router).listen(3000, () => {
  console.log('Swagger UI is available at http://localhost:3000/docs')
})