Watt, The Node.js Application Server
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
-
Error: Cannot find module '@platformatic/service'
cause One of Watt's core dependencies, such as @platformatic/service or @platformatic/runtime, is missing or incorrectly installed.fixRun `npm install` or `pnpm install` in your project root to ensure all `@platformatic/*` dependencies are correctly installed. Verify your `package.json` for `wattpm` and its peer dependencies. -
Error: `server.hostname` option must be a string
cause The `server.hostname` in your Platformatic configuration is either missing or set to an invalid type, especially after the fix in v3.52.0 where implicit defaults were changed.fixExplicitly set `server.hostname` to a valid string (e.g., `'127.0.0.1'` or `'0.0.0.0'`) in your `platformatic.json` or `platformatic.service.json` configuration file. -
TypeError: app.get is not a function
cause This error typically occurs if you are trying to use Fastify-specific methods directly on an application instance that hasn't been properly initialized as a Platformatic Service or if a plugin isn't correctly registered.fixEnsure your application is configured as a `platformatic service` and that plugins exporting Fastify routes are correctly specified in your `platformatic.json` or similar configuration under the `plugins` section. Verify the `app` object in your plugin is indeed a Fastify instance.
Warnings
- breaking Watt now requires Node.js version 22.19.0 or higher. Running on older Node.js versions will result in startup failures.
- security Multiple dependencies, including `fast-jwt`, `fastify`, and `yaml`, have received security updates. Running older versions exposes applications to known vulnerabilities.
- gotcha Prior to v3.52.0, the server hostname might have implicitly defaulted to `127.0.0.1` even when unset. This behavior was corrected, and now `server.hostname` must be explicitly set if you expect it to bind to a specific interface or `0.0.0.0` for all interfaces.
- gotcha Incorrect calculation of `--max-semi-space-size` for child processes in earlier versions could lead to suboptimal memory usage or stability issues in applications relying on multiple worker threads.
- breaking Database views are now supported as read-only entities. While a new feature, if existing code implicitly assumed all database entities were writable and interacted with views, it might lead to unexpected read-only errors if not properly handled.
Install
-
npm install wattpm -
yarn add wattpm -
pnpm add wattpm
Imports
- start
const { start } = require('wattpm')import { start } from 'wattpm' - Watt CLI
import { create } from 'wattpm'npx wattpm@latest create
- Platformatic Types
import type { PlatformaticService } from '@platformatic/service'
Quickstart
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);
});