O'Reilly logo

Sails.js Essentials by Shaikh Shahid

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building REST API in Sails.js

Let's create a new Sails.js project and develop our first Sails.js API. To create a new project, use the following command:

sails create <projectName>

To create a new API in Sails.js, you have the following two ways:

  • Create model and controller manually
  • Allow Sails.js to create them automatically

I will go for the second method as it's fairly simple and system-generated files are less prone to errors; therefore, you don't have to waste your time debugging these files. However, at the end of this chapter, we will take a look at the first method as well.

To create a new API, just execute the following command from the terminal in the project directory:

sails create api Message 

This is it. We created a skeleton of our API ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required