Chris Mendez in For Developers, Javascript, NodeJS

How to install SailsJS

Environmental

Install SailsJS

npm install sailsjs  

Install Chrome Postman

Content-Type application/json  

Quickly get started

Create a new sails app.

sails name_of_app  

Create new sails using JADE

sails new name_of_app --template=jade  

Fire up web server

sails lift  

Create a model User. You can use this in production

sails generate model user  

This is the equivalent of rails scaffold except it's using JSON API

CRUD

{
  "where": {
    },
    "limit": 2,
  "sort": "fname ASC"
}

Skipping for pagination

{
    "where": {
    },
    "limit": 2,
    "skip": 1
}

Search for people who have an "a" in their "fname"

{
    "where": {
        "fname": {
            "contains": "a"
        }
    }
}

Who's name starts with a C

{
    "where": {
        "fname": {
            "startsWith": "c"
        }
    }
}

Make requests using socket.io

io  
io.connect("http://localhost:1337");  
var socket = io.connect("http://localhost:1337");  
socket.request('/user', {} ,function(users){console.log(users)});  

Troubleshooting