TUTORIAL About Sails.js | See how to do it

by admin-kervin
Everything You Need to Know About Sails

Everything You Need to Know About Sails

Have you ever heard about Sails.js? Well, if you have no idea what it is or if you just have some basic notions about it, do not lose sight of the following article, as we will analyze it thoroughly.

The first thing we have to consider in this regard is that JavaScript continues to evolve over time, allowing all kinds of developments, thanks even to some complementary technologies appeared.

They are several softwares of frameworks those that are useful in this type of cases, and in this regard it must be said that one of the most interesting is Sails.js, taking into account that it is rather oriented towards the Back-End, allowing the creation of APIs.

TUTORIAL About Sails.js | See how to do it 1

Requirements to Use Sails.js

Well, before knowing more in detail Sails.js, you have to know that there are some requirements important to consider, and that is why we are going to show you some examples that you should know, characteristics of use, etc.

To take full advantage of Sails.js, first of all it will be important that you have the most recent version of Node.js, something that is easy to obtain if we look for the installer that exists to Windows about.

At the same time, we also need other elements among which we can mention a rich text editor in the style of Sublime Text or NotePad ++, since they will help us write the necessary codes.

Finally, do not neglect internet access for downloads of Sails.js and complementary.

TUTORIAL About Sails.js | See how to do it 2

Installation of Sails.js

Well, first of all we can say that installation Sails.js is really simple, since we just have to execute a command line from our Node.js console. For that, from the package manager write:

Nous recommandons:  Android 6.0 Nexus 4: Installation Tutorial

npm -g install sails

Executed the command, which may take a bit according to the speed of your computer, you can create a new application with the command:

sails new project Test

You should see a success message, and after that, with the following code you can lift the server:

sails lift

At this point, we will be able to open the browser of our choice, and once we visit the address http: localhost: 1337, we should be viewing these particular contents.

It would be normal at this point that it has been deployed the Home which appears by default, in which there are elements such as the steps we have to take to carry out our path with this framework.

Detailed all these aspects, it is time to meet the structure of our application.

TUTORIAL About Sails.js | See how to do it 3

Elements to Create with Sails.js

Sails.js is a fairly complete framework, as it is becoming clear, but to finish knowing it it is important that we review the directories and files important that are part of this particular development:

  • API: This is the directory in charge of managing the controllers, although it has other functions such as offering a directory called policies, which determines the authorization and access rules of the users.
  • Assets: another interesting platform that we should not stop considering, in this case one that will attract the attention of users because it offers access to static files such as js, css, images, etc.
  • Config: This directory also contains different directories, which are key in most cases for the configuration of our application, although we are going to talk more in depth now.
Nous recommandons:  Samsung Galaxy Fold Updated video tutorial to reflect changes in ...

It happens that although there are really many, one of the most important files that can be found within the Config directory is the one called connections.js, which allows managing the different connections to Databases.

You have to consider, at this point, that Sails.js comes by default with Waterline, an ORM that is useful for managing operations with relational databases and also with some non-relational ones.

Therefore, you can establish connections to a MySQL Database in this way:

someMysqlServer: {adapter: ‘sails-mysql’, host: ‘YOUR_MYSQL_SERVER_HOSTNAME_OR_IP_ADDRESS’, user: ‘YOUR_MYSQL_USER’, password: ‘YOUR_MYSQL_PASSWORD’, database: ‘YOUR_MYSQL_DB’

You can also access a nonSQL Database such as MongoDB:

someMongodbServer: {adapter: ‘sails-mongo’, host: ‘localhost’, port: 27017, // user: ‘username’, // password: ‘password’, // database: ‘your_mongo_db_name_here’},

And finally it is also possible to connect to PostgreSQL:

somePostgresqlServer: {adapter: ‘sails-postgresql’, host: ‘YOUR_POSTGRES_SERVER_HOSTNAME_OR_IP_ADDRESS’, user: ‘YOUR_POSTGRES_USER’, password: ‘YOUR_POSTGRES_PASSWORD’, database: ‘YOUR_POSTGR’

Beyond that, you just have to install the dependencies for the Database, and you can work with Sails.js.

  • Tasks: This is a directory where you will find the rules for some files, such as pipeline.js, which records the order in which js, css and templates must be compiled before being linked.
  • Views: its own name indicates it, and it does nothing more than refer to the views, which are nothing other than templates compiled on the server, which appear as HTML pages, and that through an HTTP request, allow us to see your information.

TUTORIAL About Sails.js | See how to do it 4

Creating a REST API with Sails.js

Once you have created the application, we will use it to generate a REST API, and the first thing we have to do in these types of cases is to verify that there are no problems with the server, and that it does not continue running.

Nous recommandons:  MP investigates Bank Pan after 250 GB leak in customer data

At that point we will see a model and a controller appear from the API created, and the following, once we have this basic CRUD, will be try it, for which we will have to access our user route, as follows:

As you can see, we don't have a user yet. However, Sails.js allows us create the values from the browser, so type:

http: // localhost: 1337 / user / create? name =Augusto Baldi

Once you have finished this action, you will have a first user inside the app Keep in mind that you can add all the users you want, and if necessary, it is also possible to change the name of any of them.

Regarding the different records that we include in the formulas, we can also remove them when we believe that they are already necessary, adding the following code:

http: // localhost: 1337 / user / destroy / 5

Everything we just taught you responds to what you call shortcuts, although our recommendation is that except when you go to use the deactivates, for which you have to go to blueprints.js, find shortcuts and assign the false value.

In this way the tutorial has completely ended, and although we have seen only part of Sails.js, keep in mind that it is a framework of the most potential, so you should not stop take advantage of it.

What else would you like to know about Sails.js that we can tell you in new articles?

This site uses cookies to improve your experience. Accept Read more

Privacy Policy
escort malatya escort bursa escort antalya escort konya mersin escort
konya escort antalya escort malatya escort malatya escort bursa escort hatay escort kayseri escort kahramanmaraÅŸ escort niÄŸde escort mersin escort