InProduct

Backend integration

Use the library directly from a Node backend.

InProduct is imported into your backend. It does not need a separate hosted server. After installation, save this as product.mjs and run node product.mjs:

import { slugify } from '@mp-lb/inproduct';

const createProduct = (name, existingSlugs) => {
  const slug = slugify(name);
  if (!slug) throw new Error('product name must produce a non-empty slug');
  if (existingSlugs.has(slug)) throw new Error('product slug already exists');
  return { name: name.trim(), slug };
};

console.log(createProduct('Everyday Mug', new Set()));

In a real API, validate input at your request boundary, use your application's error handling, and enforce uniqueness transactionally in your own database. Authentication, storage, catalog, cart and checkout are application responsibilities. This example's Set is not persistent storage.

MyShop backend example

apps/myshop-backend is a local-only consumer of the public storage library. It creates storage with the disk adapter and mounts the library's Node HTTP handler. apps/myshop-frontend uses the HTTP client and headless hook through Vite's proxy.

Run zap task myshop to build the libraries and start both services. File uploads persist under ignored apps/myshop-backend/.data/files across browser reloads and backend restarts. See MyShop and File storage.

The separate apps/landing-page is the public marketing site. The private core/server/tRPC packages remain shared scaffold examples; consumers of the public libraries do not need them. MyShop's file API uses the library's HTTP handler.

On this page