{"library":"nextcloud-node-client","title":"Nextcloud Node.js Client","description":"The `nextcloud-node-client` is a TypeScript-first library offering a comprehensive API to interact with Nextcloud servers from Node.js applications. Currently at version 1.8.1, it demonstrates an active development cadence with regular minor releases introducing new features like recursive file retrieval, user management, and improved sharing capabilities. The library differentiates itself by providing a rich, simple API that abstracts away the underlying Nextcloud communication protocols, supporting essential operations such as uploading and downloading files, managing folder structures, handling user accounts, creating and managing shares, and applying tags and comments to filesystem elements. A key feature is its flexible credential management, allowing configuration via environment variables (NEXTCLOUD_USERNAME, NEXTCLOUD_PASSWORD, NEXTCLOUD_URL) or Cloud Foundry's `VCAP_SERVICES`, and strongly recommending the use of Nextcloud's app-specific passwords for enhanced security. This client aims to streamline automation tasks for Nextcloud instances.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install nextcloud-node-client"],"cli":null},"imports":["import Client from 'nextcloud-node-client';","import { File, Folder, Tag, Share } from 'nextcloud-node-client';","import * as NextcloudClient from 'nextcloud-node-client';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import Client, { File, Folder, Share } from 'nextcloud-node-client';\n\n// Ensure these environment variables are set:\n// process.env.NEXTCLOUD_USERNAME\n// process.env.NEXTCLOUD_PASSWORD\n// process.env.NEXTCLOUD_URL (e.g., 'https://your.nextcloud.host')\n\n(async () => {\n    try {\n        // Create a new client. Credentials are automatically picked up from environment variables.\n        const client = new Client();\n\n        // Create a folder structure if it doesn't exist\n        const folder: Folder = await client.createFolder('my-test-folder/subfolder');\n        console.log(`Created folder: ${folder.name}`);\n\n        // Create a file within the folder\n        const fileContent = Buffer.from('Hello, Nextcloud from Node.js!');\n        const file: File = await folder.createFile('hello.txt', fileContent);\n        console.log(`Created file: ${file.name}`);\n\n        // Add a tag to the file (the tag will be created if it doesn't exist)\n        await file.addTag('nodejs-api-test');\n        console.log('Added tag to file.');\n\n        // Get the content of the created file\n        const downloadedContent: Buffer = await file.getContent();\n        console.log(`Downloaded file content: ${downloadedContent.toString()}`);\n\n        // Share the file publicly with a password and note\n        const share: Share = await client.createShare({\n            fileSystemElement: file,\n            password: 'my-secure-password',\n            note: 'Shared via nextcloud-node-client example.'\n        });\n        console.log(`File shared publicly. Share link: ${share.url}`);\n        console.log(`Share password: ${share.password}`);\n\n        // Clean up: Delete the folder, which also deletes the file and share within it\n        await folder.delete();\n        console.log(`Deleted folder: ${folder.name}`);\n\n    } catch (e) {\n        console.error('An error occurred:', e);\n        // More robust error handling might include checking error types or messages\n        if (e instanceof Error) {\n            console.error(e.message);\n        }\n    }\n})();","lang":"typescript","description":"This example demonstrates creating a Nextcloud client, managing folders and files, adding tags, retrieving file content, and creating password-protected public shares, followed by cleanup. It uses environment variables for authentication.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}