Skip to content

NPM Package Management

Microfn allows you to use any public NPM package in your serverless functions.

You can import packages directly in your code. Microfn will automatically detect import statements and install the latest version of the package during deployment. There is no need to add packages manually unless you require a specific version.

// 'lodash' will be automatically installed on deploy
import _ from 'lodash';
export default async function main(input) {
const sorted = _.orderBy(input.items, ['priority'], ['desc']);
return { processed: sorted };
}

If you need to use a specific version of a package, you can add it through the workspace settings. This is useful for pinning dependencies to ensure stability or for using older versions of packages.

  1. Navigate to your workspace.
  2. Go to Settings → Packages.
  3. Click Add Package.
  4. Enter the package name (e.g., lodash) and the desired version (e.g., 4.17.21).
  5. Click Deploy to update your workspace.

Once a package version is specified in your settings, that version will be used during deployment, overriding the automatic installation of the latest version.