Watt, The Node.js Application Server

3.52.2 · active · verified Tue Apr 21

Watt (wattpm) is Platformatic's core Node.js application server, currently at version 3.52.2. It provides a robust runtime environment for centrally managing and orchestrating multiple Node.js applications, offering built-in support for popular frameworks like Fastify, Next.js, Astro, and Express. The project maintains a very active development cycle, with frequent patch and minor releases, often multiple times a week, ensuring quick bug fixes and feature enhancements. Key differentiators include an integrated virtual mesh network for inter-service communication, high-performance logging via Pino, comprehensive monitoring with Prometheus, and distributed tracing through OpenTelemetry. This makes it suitable for modular monoliths and microservices architectures where centralized management and observability are critical.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically start a Watt server, configure a simple Fastify service with a custom plugin, and expose a '/hello' endpoint, illustrating its core runtime capabilities.

import { start } from 'wattpm';
import { writeFileSync } from 'node:fs';
import { join } from 'node:path';

async function bootstrap() {
  const configPath = join(process.cwd(), 'platformatic.service.json');
  const config = {
    server: {
      hostname: '127.0.0.1',
      port: 0 // Assigns a random available port
    },
    service: {
      openapi: {
        url: '/documentation'
      },
      routes: {
        '/hello': {
          get: {
            handler: '$.hello'
          }
        }
      }
    },
    plugins: {
      paths: [
        join(process.cwd(), 'plugin.js')
      ]
    }
  };

  writeFileSync(configPath, JSON.stringify(config, null, 2));
  writeFileSync(join(process.cwd(), 'plugin.js'), `
    async function plugin(app) {
      app.get('/hello', async (request, reply) => {
        return { message: 'Hello from Watt!' };
      });
    }
    export default plugin;
  `);

  console.log('Starting Watt server...');
  const app = await start({ config: configPath });

  console.log(`Watt server listening on ${app.url}/hello`);
  console.log('Access documentation at ' + app.url + '/documentation');

  // To stop the server programmatically (e.g., in tests or for graceful shutdown)
  // await app.close();
}

bootstrap().catch(err => {
  console.error('Failed to start Watt server:', err);
  process.exit(1);
});

view raw JSON →