Libraries

Moonbase Libraries

Moonbase libraries are in constant development (and admittedly in their infancy).

NodeJS

Typescript + Fastify example with Pino

import fastify from 'fastify';
import pino from 'pino';
 
const transport = pino.transport({
  targets: [
    {
      target: '@moonbasehq/pino',
      options: {
        projectId: 'clxaua3q10004zg0q5p7qvjyj',
        apiKey: 'moonbase_...',
      },
    },
    {
      target: 'pino-pretty',
      options: {
        colorize: true,
        translateTime: 'HH:MM:ss Z',
        ignore: 'pid,hostname',
      },
    }
  ],
  dedupe: true,
});
 
const logger = pino(transport);
 
const server = fastify({
  logger,
});
 
server.get('/', async (request, reply) => {
  request.server.log.info('Hello this is from the local app');
 
  return { hello: 'world' };
});
 
const start = async () => {
  try {
    await server.listen(3000, '0.0.0.0');
    server.log.info(`Server listening at http://0.0.0.0:3000`);
  } catch (err) {
    server.log.error(err);
    process.exit(1);
  }
};
 
logger.error('this is an example error log');
 
start();