NPM Package Management
NPM Package Management
Section titled “NPM Package Management”Microfn allows you to use any public NPM package in your serverless functions.
Automatic Installation
Section titled “Automatic Installation”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 deployimport _ from 'lodash';
export default async function main(input) { const sorted = _.orderBy(input.items, ['priority'], ['desc']); return { processed: sorted };}
Managing Specific Versions
Section titled “Managing Specific Versions”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.
Adding a Package Version
Section titled “Adding a Package Version”- Navigate to your workspace.
- Go to Settings → Packages.
- Click Add Package.
- Enter the package name (e.g.,
lodash
) and the desired version (e.g.,4.17.21
). - 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.