Learn how to use the Sails.js framework to rapidly build a new web application

Sails.js is an exciting MVC framework for Node.js. Recently the team released version 1.0 and today you’re going to learn how to use the framework to rapidly build a new website. The hype around Sails.js is real. As a veteran MVC developer, I was impressed with the extensibility, organization, flow, and speed Sails.js provides.

The team at Sails. js has done an excellent job of abstracting the MVC portion of the codebase away from the ancillary tasks of database management, authentication, authorization, setting up middleware, and anything else you can imagine. Once your project is set up the way you see fit, the MVC portion of the project is very quick. In this tutorial, I won’t be going over everything in the setup because Sails.js supports almost any tools you use. Once you start work on your project, you’ll want to go through and understand how best to meet your needs. I highly recommend going over the Concepts Section on Sails’ website for more information.

One last note about Sails.js in general; the framework really shines with a project that is well thought through and ready for development. If you start working on a project and continuously flip between the policies, routes, models, views, and controllers the framework can get a little overwhelming. It’s much easier to have the list of routes already designed before implementing the code then moving on to the controllers and so forth.

In this project, you will build a small web application for monitoring and maintaining a garden. Recently, I completed an enclosed garden for my wife and grew interested in monitoring and maintaining it remotely using an Arduino. The system will have a controller for a fountain, a GSM module for communicating with this web application, and an array of peripherals for monitoring the general health of the garden. This application will be used to store and display the metrics on the garden’s health as well as take instructions for turning the fountain on and off.

Setup Okta

First, you need to set up a new application in Okta. Log into your developer console and click on Applications and then Add Application. Okta will ask you to choose your platform which you can select Web. This will bring you to the Application Settings section of the setup phase. Name your application something meaningful, I named mine Gardino. You will likely need to change the ports on your Base URIs, Login redirects URIs, and Logout redirect URIs. By default, Sails.js uses 1337 so change 8080 to 1337.

Application settings

Press Done and you’ll be able to review your setup before moving forward. Make note of your ClientId and your Client Secret as you will need these for your application.

Create Your Sails.js Application

With your Okta application complete you can start building your application. First, you will need to install Sails. js globally using npm.

npm install sails -g

Next, you can use the Sails generator in your directory to create a new app.

sails new gardunio

You will be shown a prompt asking if you want to create a Web App or Empty project. Choose the Web App option.

Choose a template

The Web App option will automatically load some dependencies that are pretty useful out of the box. These include bootstrap, vue, and parasails. Parasails is a small wrapper around Vue.js and Lodash that is useful if you choose to use Vue.js on your front end.

The downside of this approach is it will create a whole web app with pages and models that you don’t need. You can remedy this by removing some of the irrelevant files. First, delete the views/emails. Next, delete views/layouts/layout-email.ejs . Finally, you can delete everything in the views/pages folder except homepage.ejs.

Next, in the api folder you should delete the hooks folder. You can delete the contents of api/controllers , api/models , and api/helpers . Finally, delete api/responses/expired.js and api/policies/is-super-admin.js.

Last, you will want to delete the contents of the assets/js folder. You may be wondering why you deleted all those files rather than using the Empty option. It’s a matter of deleting some extraneous things, vs going through the work of adding in missing but critical components to the application. It’s a little bit easier to remove the web app features than add back the missing components.

#node #sails #web-development #developer

How to Use the Sails.js Framework to Build a New Web Application
2.40 GEEK