Easy deployment of Meteor applications to your own server

    You can do everything you need with Meteor, and you can do it easily. This approach inspired developers to add a team meteor deploythat was supposed to magically cover all the needs for application deployment. But she didn’t close it.

    meteor deployIt works only if you use the Galaxy cloud solution (from $ 0.035 per hour) or free hosting on Meteor.com (which closes on March 25).

    You can run the application on your server: you need to assemble it for the selected platform, send it to the server and run it as an ordinary Node.js application. True, instead of starting, error messages will sprinkle. For everything to go well, it’s important to use the correct version of Node.js. Here is a guaranteed working instruction.

    Server Tuning

    You will need a server with Ubuntu 14.04 LTS. For example, droplet in DigitalOcean . Configure access to it via ssh with a key without a password and install Node.js 0.10.x.
    curl -sL https://deb.nodesource.com/setup_0.10 | sudo bash -
    apt-get install nodejs

    Install Mongo from the repository.
    apt-get install mongodb-server

    Install Forever so that the application restarts in case of problems.
    npm install -g forever

    If you need a spiderable package, install PhantomJS.
    apt-get install phantomjs

    Application Deployment

    Build the application on your local machine.
    meteor build --architecture os.linux.x86_64

    Copy meteor.tar.gz to the server (for example, in / home / meteor).
    scp /tmp/meteor.tar.gz sashagrey:/home/meteor

    Unpack the tarball on the server and install all the necessary packages.
    tar -xf meteor.tar.gz
    cd /home/meteor/bundle/programs/server && npm install

    Set environment variables.
    export PORT=80
    export MONGO_URL=mongodb://localhost:27017/meteor
    export ROOT_URL=http://example.com

    Launch the app.
    forever start /home/meteor/bundle/main.js

    Single team

    Usually I store all the meteor code in a separate folder meteorinside the project. In package.json, I add a script that performs all the steps described above and launches the application on the server (it is assumed that you can access the command with your server ssh sashagrey).
        "scripts": {
            "deploy": "cd meteor && meteor build /tmp --architecture os.linux.x86_64 && scp /tmp/meteor.tar.gz sashagrey:/home/meteor && rm /tmp/meteor.tar.gz && ssh sashagrey 'forever stopall && cd /home/meteor && tar -xf meteor.tar.gz && rm meteor.tar.gz && cd /home/meteor/bundle/programs/server && npm install && export PORT=80 && export MONGO_URL=mongodb://localhost:27017/meteor && export ROOT_URL=http://example.com && forever start /home/meteor/bundle/main.js'",

    Done. Now, to send the application to your own server and run it there, one command is enough.
    npm run deploy

    Also popular now: