Meteor JS on Clever Cloud

Lately, a lot of developpers asked us about Meteorjs support on Clever Cloud. This is indeed a growing technology out there, so I decided to test it myself.

What is Meteorjs ?

Meteor.js is based on Nodejs and is a real-time cross-platform web application framework (Web, Android and iOS). One of its main features is to automatically propagate data changes to clients in real-time or even query the database from the client (well, the client has a cache of the database which will update the remote one). It is an easy framework to build reactive applications

How to deploy on Clever Cloud

As an example of a large Meteor application, I will use TelescopeJS. It's a social news application you can configure the way you want. I'll use the version v0.14.2 since it does not require MongoDB 3.0. This is a version we will provide in a near future.

1- Clone

So first, git clone https://github.com/TelescopeJS/Telescope && cd Telescope && git checkout v0.14.2 and run it: meteor run. Then open http://localhost:3000, you should see the default page with some examples.

2- Install and build

To make it run on Clever Cloud, we have to make our own install script. This script will run when you deploy your application and build what's needed. Create an install.sh file and paste the following lines (or download it from Github):

#! /bin/bash

# Current path
currentPath=$(realpath ./)

# Install Meteorjs
curl https://install.meteor.com/ | sh
export PATH=/home/bas/.meteor:$PATH

# Install demeteorizer
cd ~/ && npm install demeteorizer

# Go back to our project
cd "$currentPath"

# Note: When using "meteorhacks:npm"
# to prevent the error: "unknown package: npm-container"
# (described in https://github.com/meteorhacks/npm/issues/49)
# uncomment the two following lines:
#meteor remove npm-container
#meteor run

# demeteorize the app
~/node_modules/.bin/demeteorizer -a "my_app" -o my_app/

# Go inside our demeteorized app to install modules
cd my_app/

# Install modules
npm install

This script will install Meteorjs on our platform, demeteorize the app (i.e. convert it as a regular node.js application) and install its modules. If you are using the package npm-container from meteorhacks, you HAVE to uncomment lines 20 and 21 (this is not our case here). Do not forget to do a chmod +x install.sh to give it execution rights.

Now we have to create our package.json (which is the file which describe your application for NPM): npm init. Open it and create a scripts section:

"scripts":{
  "install": "./install.sh",
  "start": "node my_app/main.js"
}

(my_app/main.js is a file generated by demeteorizer, do not modify this line)

Then, you can commit your changes: git add package.json install.sh && git commit -m "Clever Cloud setup"

Configuration

Once done, we need to create a Node.js application and a MongoDB addon and configure it. Open the dashboard and:

Addon

  • Add an addon
  • Select MongoDB, choose your plan and name it.
  • Click it in the blue pane on your left, go into its configuration tab and copy somewhere the Connection URI field

Application

  • Add an application
  • Choose node.js for the language
  • Choose the scalers you want (the default configuration is enough most of the time)
  • Name it
  • We don't need an addon since we've just created it
  • Environment variables: You have to create 2 of them: ROOT_URL (url of you application) and MONGO_URL (the Connection URI field you saved)
  • Follow instructions to add the remote repository, git push and it will deploy.

Your application should now be deployed, feel free to contact our support if you have any troubles!

Blog

À lire également

MateriaDB KV, Functions: discover the future of Clever Cloud at Devoxx Paris 2024

Clever Cloud is proud to present its new range of serverless products: Materia!
Company

Our new logs interface is available in public beta

You can now discover our new log stack interface and its new features!
Company

Deploy from GitLab or GitHub

Over the past few months, some customers have raised questions about CI/CD building to deploy…

Engineering