🚨 Announcement: A New Chapter for Vendure read more

Stand-alone CLI Scripts

It is possible to create stand-alone scripts that can be run from the command-line by using the bootstrapWorker function. This can be useful for a variety of use-cases such as running cron jobs or importing data.

// run-sync.ts

import { bootstrapWorker, Logger } from '@vendure/core';

import { config } from './vendure-config';
import { DataSyncPlugin, DataSyncService } from './plugins/data-sync';

const loggerCtx = 'DataSync script';

  .then(() => process.exit(0))
  .catch(() => process.exit(1));

async function runDataSync() {
  // This will bootstrap an instance of the Vendure Worker
  const { app } = await bootstrapWorker({
    plugins: [
  // Using `app.get()` we can grab an instance of _any_ provider defined in the
  // Vendure core as well as by our plugins.
  const dataSyncService = app.get(DataSyncService);
  Logger.info('Syncing data...', loggerCtx);
  try {
    const result = await dataSyncService.runSync();
    Logger.info(`Completed sync: ${result.count} items processed`, loggerCtx);
  } catch (e) {
    Logger.error(e.message, loggerCtx, e.stack);
    throw e;

This script can then be run from the command-line:

yarn ts-node run-sync.ts