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 already available on your cloud. It is a sandboxed version, so not all Node.js commands will work. You can use the npm command by connecting to your cloud over SSH.
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
- 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.
- The MODX Cloud support team will install the necessary libraries into your MODX Cloud instance and send you a notification once installed.
-
Connect to your instance using SSH, then install Gulp:
npm install -g gulpThis will put the
gulpcommand in your system path, allowing it to be run from any directory.
-
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-testWhen that completes, enter:
cd cloud-gulp-test && npm install -
Now, start Gulp:
gulp -
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:
- “What is npm?” explainer video on Youtube
- The “Gulp – The basics” screencast on Youtube
- “Getting Started with Gulp” by Travis Maynard
Node.js is a trademark of Joyent, Inc. and is used with its permission. We are not endorsed by or affiliated with Joyent.