bfast-database

raw JSON →
4.0.0-beta.2 verified Sat Apr 25 auth: no javascript

Node.js database runtime instance for Bfast::Cloud::Database, currently in beta v4.0.0-beta.2. It acts as a database-as-a-service engine that wraps MongoDB (or optionally S3 for storage) and provides a REST API for client-side operations. Key differentiators: integrates with bfast-tools CLI, supports multiple databases (MongoDB, GridFS, S3), provides JWT authentication, and offers both restart and non-restart modes. The package is part of the Bfast ecosystem and is intended for use with bfast-tools. Development appears active with recent beta releases.

error Error: Cannot find module 'bfast-tools'
cause bfast-tools is not installed globally.
fix
Run: npm install -g bfast-tools
error MongoError: Authentication failed
cause Invalid MongoDB credentials or database URI.
fix
Check DATABASE_URI env variable; ensure user/password are correct.
error TypeError: BfastDatabase is not a constructor
cause Using CommonJS require instead of ESM import.
fix
Use import BfastDatabase from 'bfast-database';
breaking bfast-database v4 is a complete rewrite; APIs from v3 are not compatible.
fix Refer to v4 documentation or migrate from v3.
deprecated bfast-tools CLI is required for server mode; standalone usage may not be fully supported.
fix Install bfast-tools globally: npm install -g bfast-tools
gotcha Environment variables must be set before starting; defaults only apply in development mode (PRODUCTION='0').
fix Set APPLICATION_ID, MASTER_KEY, PROJECT_ID, DATABASE_URI in production.
npm install bfast-database
yarn add bfast-database
pnpm add bfast-database

Initialize and start bfast-database with required environment variables.

import BfastDatabase from 'bfast-database';

const db = new BfastDatabase({
  applicationId: process.env.APPLICATION_ID || 'bfast',
  masterKey: process.env.MASTER_KEY || 'bfast',
  projectId: process.env.PROJECT_ID || 'bfast',
  databaseURI: process.env.DATABASE_URI || 'mongodb://localhost/bfast',
  port: parseInt(process.env.PORT || '3000'),
  production: process.env.PRODUCTION === '1',
  rsaKey: process.env.RSA_KEY ? JSON.parse(process.env.RSA_KEY) : undefined,
  rsaPublicKey: process.env.RSA_PUBLIC_KEY ? JSON.parse(process.env.RSA_PUBLIC_KEY) : undefined
});

await db.start();
console.log('bfast-database running on port', db.port);