Setting Up Dev Environment For Node.Js With Sails.Js(MVC) And MongoDb

Sails.js make it easy to build custom, enterprise-grade Node.js apps. It is designed to mimic the MVC pattern of frameworks like Ruby on Rails, but with support for the requirements of modern apps: data-driven APIs with scalable, service-oriented architecture. It’s especially good for building chat, realtime dashboards


Here im gonna show you how you can set up a node.js + Sails.js environment to get started with node.js in a better & Excellent node.js framework Sails.js and MongoDb(noSQL) .

My platform is Apache2 & Ubuntu 12.04.

Note1:Before Installing Sails.js We need to Install Node.js & npm.

Note2:I recommend you to update your system with this PPA (Personal Package Archives) so you can install an up-to-date version of node.js:

Install the latest version of Node.js

$ sudo apt-get install python-software-properties
$ sudo add-apt-repository ppa:chris-lea/node.js
$ sudo apt-get update
$ sudo apt-get install nodejs npm
$ node -v


Install Sails.js

$ sudo npm -g install sails


Install MongoDb

$  sudo apt-get install mongo


Create New App in Sails.js

$ sails new testProject


Install nodemon

$  npm install nodemon -g


Connecting the app with mongoDb.

Put the below code in this file: /config/adapters.js

  module.exports.adapters = {
  // If you leave the adapter config unspecified
  // in a model definition, ‘default’ will be used.
  'default': 'mongo',
    mongo: {
    module   : 'sails-mongo',
    url      : 'mongodb://localhost:27017/sails1'


Start the mongoDb server by running below code @terminial

$ mongod


Run the testProject

Note:We are using nodemon to automate listening for our app’s source code change and restart the node server with the latest update .(This will be really helpful while developement)

$ cd testProject
  $ nodemon app.js

Now your app will be available @http://localhost:1337

—Enjoy Working with Sails.js guys…Happy coding..

Leave a Reply

Your email address will not be published. Required fields are marked *