Sample Node service app that connects to a Laserfiche Cloud or Self-Hosted Repository. Sample Code
- Node 18 LTS
- TypeScript
- CA, EU, or US Cloud Web Client account
- Proper fetch client
-
Log in to your account using Web Client as an administrator:
-
Using the app picker, go to the 'Account' page.
-
Click on the 'Service Principals' tab.
-
Click on the 'Add Service Principal' button to create an account to be used to run this sample service.
-
Add access rights to the repository and click the 'Create' button.
-
View the created service principal and click on the 'Create Service Principal Key(s)' button.
-
Save the Service Principal Key for later use.
- Navigate to Laserfiche Developer Console:
- Click on the 'New' button and choose the 'Create a new app' option.
- Select the 'Service' option, enter a name, and click the 'Create application' button.
- Select the app service account to be the one created on step 1 and click the 'Save changes' button.
- Click on the 'Authentication' Tab and create a new Access Key.
- Select the first option (i.e. Create a public 'Access Key'...).
- Click the 'Download key as base-64 string' button for later use.
- Click OK.
- Select the required scope(s) in the 'Authentication' tab. For running this sample project, both 'repository.Read' and 'repository.Write' scopes are required.
- Click on the 'Update scopes' button.
- Using the app picker, go to the 'Repository Administration' page and copy the Repository ID
- In the root directory of this project, create a .env file containing the following lines:
AUTHORIZATION_TYPE="CLOUD_ACCESS_KEY"
SERVICE_PRINCIPAL_KEY="<Service Principal Key created from step 1>"
ACCESS_KEY="<base-64 Access Key string created from step 2>"
REPOSITORY_ID="<Repository ID from the 'Repository Administration' page>"
- Note: The .env file is used in local development environment to set operating system environment variables. DO NOT check-in the .env file in Git.
See this page.
- Open a terminal window.
- Enter the following commands:
npm i
npm run start
These commands will install, compile, and execute this program which will print out the repository information in the output window. Note: This project uses the @laserfiche/lf-repository-api-client-v2 NPM package. See Laserfiche Repository API Documentation.