Node.js

Using Node.js in MODX Cloud

What is Node.js®?

Node.js is tool that allows you to run server-side JavaScript applications. Most notably npm, its command-line package installer tool that is akin to gem, apt-get, yum, pip, etc.

npm makes it easy for JavaScript developers to share and reuse code, and it makes it easy to update the code that you're sharing.

You can use npm to include function-specific bits of well-tested code from other developers in your own projects. This can be front-end things like Angular.js, or back-end toolkits to help you develop projects more quickly like Grunt, Bower and other automation or build tools.

Installing Node.js on your Cloud

Node.js is available going to he Add-ons tab of your Cloud and locating Compass/Sass/Node.js from the Software section and clicking to toggle to trigger activation. This is a semi-manual process at this time and the team will enable it as quickly as possible during business hours. 

Using Node.js in MODX Cloud

Node.js is available in MODX Cloud to aid in site development or augment a website’s functionality. Using Node requires that you interact with the MODX Cloud via SSH.

In MODX Cloud, Node is not intended be used to run full blown server-side JavaScript applications visited by the public. Good uses of Node in MODX Cloud include helper utilities like:

  • Bower—Web sites are made of lots of things — frameworks, libraries, assets, and utilities. Bower manages all these things for you.

  • Grunt—The less work you have to do when performing repetitive tasks like minification, compilation, unit testing, linting, etc, the easier your job becomes. After you’ve configured it through a Gruntfile, a task runner can do most of that mundane work for you—and your team—with basically zero effort.

  • Gulp—A streaming build system that accomplishes many of the same things as Grunt, albeit in a very different way.

Example: Install Gulp in MODX Cloud

  1. Install Node.js. Go he Add-ons tab of your Cloud and locating Compass/Sass/Node.js from the Software section and clicking to toggle to trigger activation. 

  2. The MODX Cloud support team will install the necessary libraries into your MODX Cloud instance and send you a notification once installed.

  3. Connect to your instance using SSH, then install Gulp:

    npm install -g gulp

    This will put the gulp command in your system path, allowing it to be run from any directory.

  1. Now you need to install a sample task file for your project. Grunt by itself doesn’t do anything. An example Gruntfile demo that includes many helpful utilities can be used as follows:

    git clone https://github.com/Omeryl/cloud-gulp-test

    When that completes, enter:

    cd cloud-gulp-test && npm install

  2. Now, start Gulp:

    gulp

  3. When Gulp is running, you can see it in action by executing the following command from the CLI:

    cp -R www/index.html dist /www/

In this demo, the following things are used, as indicated in the gulpfile.js, including installing dependencies automagically for you as indicated in the package.json file.

 

Learning More

Here are some additional resources to help you learn more about leveraging Node.js in MODX Cloud:

Node.js is a trademark of Joyent, Inc. and is used with its permission. We are not endorsed by or affiliated with Joyent.

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.