Gulp provides a tool for build task execution in Node.js environments that’s comparable Gradle in Java environments.

The Node.js API makes it easy to write down Gulp pipelines that generate proxy modules.

The proxy-generator.js module provides a generate() factory function, which return a Node.js Transform that takes the Gulp Vinyl descriptor for a proxy service directory as input and produces the Gulp Vinyl wrapper for a generated proxy module as output.

Following the Gradle project convention (where ml-modules/root/ds contains proxy service directories), the example below of a gulpfile.js pipes proxy service directories to the proxy module generator then pipes the generated proxy modules to the lib directory for the project:

'use strict';
const gulp = require('gulp');
const proxy = require('marklogic/lib/proxy-generator.js');
function proxygen() {
return gulp.src('ml-modules/root/ds/*')
exports.proxygen = proxygen;

The following Gulp command command is used to process this gulfile.js:

gulp proxygen

The Node.js client modules can use require() to import the generated proxy modules in the usual way and then construct proxy objects and call the methods of the proxy objects to invoke the server endpoints.

Generated Modules

Similar to the Interface generated for Java, the JavaScript module generated for Node.js defines and exports a JavaScript class with the following characteristics:

• A constructor that takes a database client with the host, port, and authentication for the
server also as an optional service declaration (where this optional service declaration
specifies a directory in the modules database with custom endpoints that implement the
interface for the service).

• A static on() method that takes the database client and optional service declaration
parameters of the constructor and provides a convenience for instantiating the class.

• A method for each function declared in the proxy service directory.

• If any of these functions takes a session parameter, a createSession() method for
constructing a ServiceState argument.

• JSDoc documentation comments for the class and each method for generating reference documentation where the content of the JSDoc comments uses the desc properties from the service declaration and *.api function declarations.Total Words: 

If you like this post, don’t forget to share 🙂

This article is written by our awesome writer
Do you like Zubeen's articles?  Follow on social!
Comments to: How to Using Gulp to Generate Models In Node.js

Your email address will not be published. Required fields are marked *

Attach images - Only PNG, JPG, JPEG and GIF are supported.

New Dark Mode Is Here

Sign In to access the new Dark Mode reading option.

Join our Newsletter

Get our monthly recap with the latest news, articles and resources.

By subscribing you agree to our Privacy Policy.

Latest Articles

Explore Tutorials By Categories


Codeverb is simply an all in one interactive learning portal, we regularly add new topics and keep improving the existing ones, if you have any suggestions, questions, bugs issue or any other queries you can simply reach us via the contact page


Welcome to Codeverb

Ready to learn something new?
Join Codeverb!

Read Smart, Save Time
    Strength indicator
    Log In | Lost Password