Month: April 2017

CRUD in Sails.js and Node.js

Disable Blueprints First of all you need to disable all existing blueprints in config/blueprints.js . JavaScript 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 /** * Blueprint API Configuration * (sails.config.blueprints) * * These settings are for the global configuration of blueprint routes and * request options (which impact the behavior of blueprint actions). * * You may also override any of these settings on a per-controller basis * by defining a '_config' key in your controller definition, and assigning it * a configuration object with overrides for the settings in this file. * A lot of the configuration options below affect so-called "CRUD methods", * or your controllers' `find`, `create`, `update`, and `destroy` actions. * * It's important to realize that, even if you haven't defined these yourself, as long as * a model exists with the same name as the controller, Sails will respond with built-in CRUD * logic in the form of a JSON API, including support for sort, pagination, and filtering. * * For more information on the blueprint API, check out: *!/documentation/reference/blueprint-api * * For more information on the settings in this file, see: *!/documentation/reference/sails.config/sails.config.blueprints.html * */ module.exports.blueprints = {   /***************************************************************************   *                                                                          *   * Action routes speed up the backend development workflow by               *   * eliminating the need to manually bind routes. When enabled, GET, POST,   *   * PUT, and DELETE routes will be generated for every one of a controller's *  ...

Read More

Create new Api in Sails.js

Create new Api JavaScript 1 sails generate api Product It will create a new Product model and ProductController file . Add Model Attributes JavaScript 12345678910111213141516171819 /** * Product.js * * @description :: TODO: You might write a short summary of how this model works and what it represents here. * @docs        :: */ module.exports = {   attributes: {    name : {     type : 'string'   },   qty :{     type : 'integer'   }  }};   Let me run the project now by using sails lift Shell 1 sails lift Product collection has been created successfully in MongoLab. Source Code   Want to learn more about Sails.js ? Please enroll into my course on Udemy: Node:js : Building Rest Apis with Sails.js for only $15 :…...

Read More

Node.js: Connecting Sails.js App to MongoLab

Signup MongoLab First of all you need to create a new account at MongoLab. After created account you need to create a new deployment in Mongolab. Make sure you have selected free sandbox You also need to create a new database with this new sandbox. Create a new User   To connect MongoLab with Sails.js . You need to create a new user . Create new Connection in Sails Now you have to create a new connection in sails.js app. First of all you need to install mongodb driver Shell 1 npm install --save sails-mongo Open your connections.js  file in Sails.js app. Create a new mongoLabServer connection object   To connect Sails.js app to MongoLab you need to use your mongo uri Shell 1 mongodb://<dbuser>:<dbpassword> After created connection you need to tell your default connection to sails.js app. Open models.js from config/models.js and add mongoLabServer connection to models object.   Run your sails project Shell 1 sails lift Your project will be running on PORT 1337 . You sails app has been connected to MongoLab   If you want to learn more about Sails.js and Node.js. I have created a new course Udemy. Here is the link of my course Nodejs: Building Rest Apis with...

Read More

Implement Lazy Loading in Angular 4

 Code     Demo Getting Setup I am going to use Angular-cli to create angular project. Installing angular cli Shell 1 npm install -g angular-cli Creating new project Shell 1 ng new lazy-demo I have divided this app into three angular module 1. App Module App module is a main module. This is our entry module 2. Customers Module Customers module is a feature module.This customer module will have the customer-list component . This customer-list component will fetch the customers from firebase database.I am going to use firebase database to get data from server. 3. Departments Module Departments module is also a feature...

Read More

Build Rest API with Node.js and Sails.js

What is Sails.js ? Sails is a Javascript framework designed to resemble the MVC architecture from frameworks like Ruby on Rails. It makes the process of building Node.js apps easier, especially APIs, single page apps and realtime features, like chat. What we will Build ? In this part we will build a rest api for blog. Each user can create many blog posts.There is a one to many relationship between user and post. Each category has many posts,One to many relationship between category and post     Getting Started with Sails cli To install sails.js you must have installed Node.js on your...

Read More
  • 1
  • 2