Sails.js support for Node.js


Introduction

Sails.jsexternal link is the MVC framework for Node.js, designed to emulate the familiar MVC pattern of frameworks, with support for the requirements of modern apps: data-driven APIs with a scalable, service-oriented architecture.

Objects

This extension, when Sails.js library is found in the source code, may create the following objects:

Icon Description
NodeJS Get Operation
NodeJS Post Operation
NodeJS Put Operation
NodeJS Delete Operation
NodeJS Patch Operation
NodeJS Any Operation

Example

Example application from Sails.js:

Server

Create a server app.js:

var sails = require('sails');

sails.lift({}, function (err) {
  if (err) {
    console.log('Error occurred lifting Sails:', err);
    return;
  }
});

This will give the following result:

Routes

Routes control at config/routes.js:

...
'GET /site/:idSite' : { controller: "Site", action: "getSite", rel: RelServices.REL_ENUM.GET_VIEWED_SITE },
...
'PUT /alert' : { controller: "Alert", action: "putAlert", rel: RelServices.REL_ENUM.PUT_ALERT, profile: ProfileServices.PROFILE_ENUM.OPERER },
...
'PATCH /alert/:idAlert': { controller: 'Alert', action: 'patchAlert',  rel: RelServices.REL_ENUM.PATCH_ALERT,  profile: ProfileServices.PROFILE_ENUM.OPERER },
...

Controller actions

controllers/SiteController.js

...
self.getSite = function (req, res) {
  ...
  var promise = Site.findOne({
    idSite: idSite
  });
  ...
};
...

controllers/AlertController.js

...
self.putAlert = function (req, res) {
  ...
  var promise = Alert.findOne({
    idAlert: idAlert
  });
  ...
};

self.patchAlert = function (req, res) {
  ...
  var promise = Alert.findOne({
    idAlert: idAlert
  });
  ...
};
...

Model definition

models/Site.js

...
self.connection = 'postgresqlServer';

self.tableName = 'T_SITE';

self.attributes = {
  ...
}
...

models/Alert.js

...
self.connection = 'postgresqlServer';

self.tableName = 'T_ALERT';

self.attributes = {
  ...
}
...

Transaction from getSite, putAlert, patchAlert functions to database when using the SQL Analyzer: