Scripting Clever Tools with NodeJS is more fun … And more efficient

Philippe Charrière
2 min readSep 12, 2017

--

Day to day, I have to prepare demonstrations, POC, … for prospective customers, and when the demonstration is done, most of the time, I drop it, and I restart the same creation process, again and again and …

To simplify my work I use the Clever Tools. The Clever Tools project is the Command Line Interface for Clever Cloud. With this CLI, you can provision Virtual Machines, scale application, restart application… from your terminal without using the Clever Cloud Administration Console.

Ok, I dislike shell scripting, but you have to know we can use NodeJS as shell replacement for bash 😁. It’s simple, add #!/usr/bin/env node to the header of your JavaScript file and do a chmod + x your_file.js , now you file is executable, you can run it like that: ./your_file.js .

A little helper to execute shell commands

I just need a little (less than 13 lines) helper before scripting the CLI:

So, it’s very easy to use:

And now 🥁 …

Imagine that I want to create an ExpressJS application (because I ❤️ Express) and deploy it quickly on Clever Cloud. I will write this:

Create the Express project:

This is not the “Clever” part, but we need it, this will generate the files of the web application:

The “Clever” part:

Now, I need to:

  • Provision a VM
  • Generate a Git repository
  • And finally push (deploy) my application on Clever Cloud

The script is very simple (and useful)

That’s all, and it’s simple. Now, I need less than 1 minute to generate and deploy my application.

This ability, offered by Node is very powerful (eg, currently I’m working on a deployment server in order to provision a VM from a feature branch in my DVCS, an other side project). So, I let you find some ideas (And I’m curious to read you).

I plan to store my recipes here: https://github.com/k33g/casti (next step: create a CI/CD platform for little teams with the CLI and NodeJS — stay tuned 😉)

Don’t hesitate to contribute, comment, etc…

--

--