Skip to content
Select documentation version
Navigation
On this page

Programmatic API

Platformatic DB allows starting and managing database instances programmatically using JavaScript, offering a flexible way to integrate database operations into your applications or scripts.

import { create } from '@platformatic/db'

const app = await create('/path/to/platformatic.db.json')

await app.start() // This starts the server.
console.log('Server URL:', app.url)

const res = await fetch(app.url)
console.log('Server response:', await res.json())

// Additional operations can be performed here.

await app.close() // This stops the server.

Customizing Configuration

You can customize the server configuration to meet specific requirements, such as setting a custom hostname or database connection string:

import { create } from '@platformatic/db'

const app = await create('/path/to', {
  server: {
    hostname: '127.0.0.1',
    port: 0
  },
  db: {
    connectionString: 'sqlite://test.sqlite'
  },
})

await app.start() // this will start our server

console.log('URL', app.url)

const res = await fetch(app.url)
console.log(await res.json())

// do something

await app.close()

For more details on how this is implemented, read Platformatic Service Programmatic API.

Issues

If you run into a bug or have a suggestion for improvement, please raise an issue on GitHub.

Reading time
1 min read
View as
Markdown
Contribute
Edit this page