Installing Sailsjs On WebfactionPosted: Tags: code,sailsjs,webfaction,nodejs
Once you have developed an app in sailsjs locally, you may want to install it on a server in the cloud to showcase to your friends. I have been using webfaction as a server for almost a decade and I'll heartily recommend them. In this post, I'll explain how to install sailsjs on webfaction and serve it to the world.
Since sailsjs is built on nodejs, first you need to install nodejs. Webfaction has a one-click installer for nodejs, but I couldn't get sailsjs running with it. So I'm going to show you how to install nodejs from sources outside of these installers.
First step is to download nodejs sources
ssh [email protected] mkdir ~/nodesrc cd ~/nodesrc wget http://nodejs.org/dist/v0.10.28/node-v0.10.28.tar.gz tar -xzf node-v0.10.28.tar.gz
Now that we have downloaded the source, let us compile and install nodejs. We need python for it. I'm on web37 server in webfaction system and python2.4 is the default python version in it. We need 2.7 for compiling. So let us make the 2.7 the default one.
cd node-v0.10.28 alias python=python2.7 python configure --prefix=$HOME make && make install
Let us verify if everything went ok.
it should return:
Installing nodejs also install npm, the node package manager. Let us confirm it. Type,
You should see,
I recommend using a virtual environment like nave while installing locally. In a local machine it is possible that you use multiple nodejs or sailsjs versions. That may not be the case at server-side, so there is no need to install a virtual environment at the server-side.
Let us install the latest beta in the server.
npm install [email protected] -g
If you want to install only the stable version of sailsjs, then, the command is:
npm install sails -g
This will install sails globally in your server. Let us verify the installation:
This should give you something like:
Exposing Sailsjs app to the world
Hosting at Webfaction involves creating domains, applications, and websites. A website record ties a domain and application; a domain would be either a top-level domain or a sub-domain of the one that you already host. In this post, I describe only about creating an application.
In 'Domains/Websites' tab, select, 'Applications'. Then select on 'Add new application'. Give a suitable app name, select 'custom' as app category and 'custom app (listening on port)' as the application type.
When you save the record, it will show you a custom port number in which this app will listen. Note it down. Also note down the path of the app. It is normally,
You have to transfer your app to this directory. It can be via traditional way of ftp. But I suppose that you use a git repo for your code (if not you should). Webfaction accounts have git installed by default and so you should git clone your repo into the app home directory. In a later post, I will explain how to deploy app via a tool like flightplan.
Once you have transferred the sailsjs app, ssh into your webfaction account and lift the app to serve to the world.
ssh [email protected] cd $HOME/webapps/<name> sails lift
If you go to your browser and type the domain name, you will see .... a 502 – Bad Gateway error. Oops. This is not what you wanted to see. This error indicates that the front-end web server is not able to communicate to your sails app.
Now let us try again. Terminate your sails app by pressing ctrl-c. I asked you to note down the custom port in which the app listens. Here comes its use.
node app.js --port=<portnumber>
Now browse to the domain and you should see your app. I can see a smile in your face. Keep it up.