### Setting up Example Environment Source: https://github.com/marklogic/node-client-api/blob/master/examples/1readme.txt Execute the 'setup.js' script to prepare the MarkLogic Node.js Client API examples. This script prompts for MarkLogic admin credentials, creates users, loads sample data, and copies example scripts. ```bash node examples/setup.js ``` -------------------------------- ### Setup Project Dependencies Source: https://github.com/marklogic/node-client-api/blob/master/typescript-test-project/README.md Installs the parent marklogic package, TypeScript, and type dependencies. Run this once to set up the project for type checking. ```bash cd typescript-test-project npm run setup ``` -------------------------------- ### Running All Example Scripts Source: https://github.com/marklogic/node-client-api/blob/master/examples/1readme.txt Execute all example scripts in the MarkLogic Node.js Client API using the 'all.js' script. This is useful for a comprehensive test of the API's capabilities. ```bash node examples/all.js ``` -------------------------------- ### Running a Query-by-Example Script Source: https://github.com/marklogic/node-client-api/blob/master/examples/1readme.txt Execute the 'query-by-example.js' script to demonstrate query-by-example functionality with the MarkLogic Node.js Client API. Ensure you have completed the setup steps. ```bash node query-by-example.js ``` -------------------------------- ### Install Mocha Globally Source: https://github.com/marklogic/node-client-api/blob/master/CONTRIBUTING.md Install Mocha globally to run the project's test suite. This only needs to be done once. ```bash npm install mocha -g ``` -------------------------------- ### Install Node.js Client API without Optional Dependencies Source: https://github.com/marklogic/node-client-api/blob/master/KERBEROS.md Use this command to install the Node.js Client API while skipping optional dependencies like the 'kerberos' module. This is useful if you do not intend to use Kerberos authentication. ```bash npm install --no-optional ``` -------------------------------- ### Start MarkLogic Service with Docker Source: https://github.com/marklogic/node-client-api/blob/master/CONTRIBUTING.md Use this command to create a Docker container with the MarkLogic service. The service may take a minute or two to initialize. ```bash docker-compose up -d --build ``` -------------------------------- ### Install MarkLogic Node Client Source: https://github.com/marklogic/node-client-api/blob/master/README.md Install the marklogic package as a dependency for your Node.js project using npm. ```bash npm install marklogic --save ``` -------------------------------- ### Install MarkLogic Node Client for Windows (v2.9.1) Source: https://github.com/marklogic/node-client-api/blob/master/README.md For Windows OS, use the --ignore-scripts flag for Node Client 2.9.1. ```bash npm install marklogic --save --ignore-scripts ``` -------------------------------- ### Generate Project Documentation Source: https://github.com/marklogic/node-client-api/blob/master/CONTRIBUTING.md Build the reference documentation locally from the root directory of the MarkLogic package after installing project dependencies. The documentation is generated in the './doc' directory. ```bash npm run doc ``` -------------------------------- ### Reloading Sample Data Source: https://github.com/marklogic/node-client-api/blob/master/examples/1readme.txt Use the 'before-load.js' script to reload the sample data into the MarkLogic database. This is helpful for resetting the environment before running examples. ```bash node examples/before-load.js ``` -------------------------------- ### Example: Testing for Type Errors Source: https://github.com/marklogic/node-client-api/blob/master/test-typescript/README.md Demonstrates how to write TypeScript code that should pass type checking and how to intentionally write code that should fail type checking to verify type definitions. ```typescript // This should work fine ✅ const good: DatabaseClientConfig = { authType: 'digest' }; // This should fail ❌ (uncomment to test) // const bad: DatabaseClientConfig = { // authType: 'invalid-type' // }; ``` -------------------------------- ### Generate JSDoc API Documentation Source: https://github.com/marklogic/node-client-api/blob/master/etc/marklogic-template/README.md Run this command from the root project directory to generate the API documentation using the provided template. The output will be placed in the 'doc/' subdirectory. ```bash gulp doc ``` -------------------------------- ### Create MarkLogic Database Client (Progress Data Cloud) Source: https://github.com/marklogic/node-client-api/blob/master/README.md Creates a database client for connecting to Progress Data Cloud. Configure with apiKey, host, authType, and optionally basePath and accessTokenDuration. ```javascript // For Progress Data Cloud const db = marklogic.createDatabaseClient({ apiKey: 'changeme', host: 'example.dev.progress.cloud', authType: 'cloud', // basePath is optional. basePath: '/marklogic/test', // accessTokenDuration (in seconds) is optional and can be used to customize the expiration of the access token. accessTokenDuration: 10, // enableGzippedResponses is optional and can be set to true in order to request MarkLogic to compress the response for better performance, // the client will automatically decompress the response before it returns a value. enableGzippedResponses: true }); ``` -------------------------------- ### Deploy Test Application to MarkLogic Source: https://github.com/marklogic/node-client-api/blob/master/CONTRIBUTING.md After the Docker container is initialized, deploy the test application to the MarkLogic service. This involves changing to the test-app directory and running Gradle commands. ```bash cd test-app ./gradlew -i mlDeploy ./gradlew -i -Penv=e2e mlLoadData mlLoadModules ``` -------------------------------- ### Create MarkLogic Database Client (Default) Source: https://github.com/marklogic/node-client-api/blob/master/README.md Creates a database client for connecting to a MarkLogic instance using default authentication (DIGEST). Ensure to set enableGzippedResponses to true for better performance. ```javascript const marklogic = require('marklogic'); const db = marklogic.createDatabaseClient({ host: 'localhost', port: '8000', database: 'Documents', user: 'admin', password: 'admin', authType: 'DIGEST', // enableGzippedResponses is optional and can be set to true in order to request MarkLogic to compress the response for better performance, // the client will automatically decompress the response before it returns a value. enableGzippedResponses: true }); ``` -------------------------------- ### Run Runtime Tests (One Command) Source: https://github.com/marklogic/node-client-api/blob/master/test-typescript/README.md A combined command to first compile TypeScript tests to JavaScript and then execute them with mocha against a MarkLogic server. ```bash npm run test:compile && npx mocha test-typescript/*.js # Run compiled tests against MarkLogic ``` -------------------------------- ### Create MarkLogic Database Client (OAuth) Source: https://github.com/marklogic/node-client-api/blob/master/README.md Creates a database client for connecting to MarkLogic using OAuth authentication. Provide host, port, authType, and the oauthToken. ```javascript // For OAUTH const db = marklogic.createDatabaseClient({ host: 'localhost', port: '8000', authType: 'oauth', oauthToken: '' }); ``` -------------------------------- ### Run Entire Test Suite Source: https://github.com/marklogic/node-client-api/blob/master/CONTRIBUTING.md Execute the complete test suite using Mocha. This command may take several minutes to finish. ```bash mocha test-basic -timeout 0 ``` -------------------------------- ### Ingesting Documents using writeAll API Source: https://github.com/marklogic/node-client-api/wiki/Data-Movement-in-the-Node.js-API The writeAll() function is used for ingesting documents into MarkLogic. It is equivalent to the DMSDK WriteBatcher and accepts an options object for configuration. ```APIDOC ## writeAll(options) ### Description Ingests documents into MarkLogic using the Node.js client API. This function is equivalent to the DMSDK WriteBatcher. ### Method Not applicable (JavaScript function call) ### Parameters #### Options Object - **options** (object) - Required - An object containing configuration properties for the write operation. Refer to the provided images and JS Docs for detailed properties. ### Request Example ```javascript // Example usage (refer to external JS file for full example) const documents = [ { uri: "doc1.json", content: { key: "value1" } }, { uri: "doc2.json", content: { key: "value2" } } ]; documentsApi.writeAll(documents, { /* options */ }); ``` ### Response Refer to JS docs for detailed response information. ``` -------------------------------- ### Run Specific Test Group or Single Test Source: https://github.com/marklogic/node-client-api/blob/master/CONTRIBUTING.md To run a single test or a 'describe' group, use the '-g' flag with the description text from the 'it' or 'describe' function. ```bash mocha test-basic -timeout 0 -g 'optic-update fromParam tests' ``` ```bash mocha test-basic -timeout 0 -g 'test bindParam with qualifier' ``` -------------------------------- ### Run Runtime Tests Source: https://github.com/marklogic/node-client-api/blob/master/test-typescript/README.md Compile TypeScript tests to JavaScript and then run them against a MarkLogic server using mocha. This verifies that types match runtime behavior. ```bash npm run test:compile # Compile TypeScript tests to JavaScript npx mocha test-typescript/*.js # Run compiled tests against MarkLogic ``` -------------------------------- ### Exporting Documents using readAll API Source: https://github.com/marklogic/node-client-api/wiki/Data-Movement-in-the-Node.js-API The readAll() function is used for exporting documents from MarkLogic, acting as an equivalent to the DMSDK ExportListener. It handles document input and output streams. ```APIDOC ## readAll(options) ### Description Exports documents from MarkLogic. This function is equivalent to the DMSDK ExportListener and manages streams for document input and output. ### Method Not applicable (JavaScript function call) ### Parameters #### Options Object - **options** (object) - Required - An object containing configuration properties for the read operation. Refer to the provided images and JS Docs for detailed properties. ### Return Value - **stream.Duplex** - A duplex stream that receives document URIs and outputs document descriptors with content. ### Request Example ```javascript // Example usage (refer to external JS file for full example) const readStream = documentsApi.readAll({ /* options */ }); readStream.on('data', (docDescriptor) => { console.log('Received document:', docDescriptor.uri); // Access docDescriptor.content if needed }); readStream.on('end', () => { console.log('Finished reading.'); }); // To provide input URIs (if applicable for the specific use case): // readStream.write('doc1.json'); // readStream.end(); ``` ### Response - **stream.Duplex** - Outputs document descriptors containing document content and/or URI. ``` -------------------------------- ### Update Local MarkLogic Package Source: https://github.com/marklogic/node-client-api/blob/master/typescript-test-project/README.md Reinstalls the local marklogic package after making changes to the parent package. Use the quick method for faster updates. ```bash # Quick way - just reinstall the local package npm install .. ``` ```bash # Or full clean reinstall rm -rf node_modules package-lock.json npm run setup ``` -------------------------------- ### Collecting Document URIs with queryAll API Source: https://github.com/marklogic/node-client-api/wiki/Data-Movement-in-the-Node.js-API The queryAll() function retrieves document URIs from the database, similar to the DMSDK QueryBatcher. It returns a stream.Readable with document URI output. ```APIDOC ## queryAll(query, options) ### Description Collects document URIs from the database. This function is equivalent to the DMSDK QueryBatcher and returns a stream of document URIs. ### Method Not applicable (JavaScript function call) ### Parameters #### query - **query** (object) - Required - The query to execute for selecting documents. #### options - **options** (object) - Optional - An object containing configuration properties for the query operation. Refer to the provided images and JS Docs for detailed properties. ### Return Value - **stream.Readable** - A readable stream that outputs document URIs. ### Request Example ```javascript // Example usage (refer to external JS file for full example) const query = { // ... query definition ... }; documentsApi.queryAll(query, { /* options */ }) .on('data', (uri) => { console.log('Found URI:', uri); }) .on('end', () => { console.log('Finished querying.'); }); ``` ### Response - **stream.Readable** - Outputs document URIs. ``` -------------------------------- ### Create Documents in a Collection Source: https://github.com/marklogic/node-client-api/blob/master/README.md Inserts two documents into a specified collection in the MarkLogic database. Handles success and error responses by logging the JSON output. ```javascript db.createCollection( '/books', {author: 'Beryl Markham', ...}, {author: 'WG Sebald', ...} ) .result(function(response) { console.log(JSON.stringify(response, null, 2)); }, function (error) { console.log(JSON.stringify(error, null, 2)); }); ``` -------------------------------- ### Run Type Checking Only Source: https://github.com/marklogic/node-client-api/blob/master/test-typescript/README.md Execute TypeScript compilation without generating JavaScript files to check for type errors. This is a fast feedback mechanism. ```bash npm run test:types ``` -------------------------------- ### Test TypeScript Types Source: https://github.com/marklogic/node-client-api/blob/master/typescript-test-project/README.md Runs TypeScript's compiler in check-only mode to validate type safety without generating JavaScript output. ```bash npm test ``` ```bash npm run typecheck ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.