{ sailsit }

Sails Js Tutorials for Beginners and Forum

Have a Question?

If you have any question you can ask below or enter what you are looking for!

Autoreload

As almost all of the developers find it difficult to stop sails and run it again for any changes done in the code.
Today we will use a npm package which provides auto reloading of sails whenever there is a change in the code.

Let’s get started

1. Creating SailsJs Project

Follow the below tutorial for setting up SailsJs
Setting up sails project

2. Installing Packages

For this autoreload feature, we will be using sails-hook-autoreload package created by Scott Gress

To install the package use the below command

FOR SAILS v0.12.x: 
npm install sails-hook-autoreload@for-sails-0.12 --save

 

FOR SAILS 1.0: 
npm install sails-hook-autoreload --save

 

4. Configuration

Now we can create a config file autoreload.js in config directory.
In this file you can define the code base changes for which you need the autoreload feature to work

Create a file autoreload.js in config (if not exist)
Paste the below code in config/autoreload.js

module.exports.autoreload = {
  active: true,
  usePolling: false,
  dirs: [
    "api/models",
    "api/controllers",
    "api/services",
    "config/locales"
  ],
  ignored: [
    // Ignore all files with .ts extension
    "**.ts"
  ]
};

You can make changes in this file as per your need

For more info related to configuration you can explore the github repo
https://github.com/sgress454/sails-hook-autoreload

5. Start Sails

Now start your sails application using below command

sails lift

This completes the setup of the autoreload package

You can find the source code for the tutorial at below URL
SailsAppAutoReload

You can also watch the video which will show the live working of autoreload package

(2) Comments

  1. Wow nice utility… I pretty much just use nodemon rather than sails lift…So i would do a ‘nodemon app.js’ and that would lift my sails app with monitoring…

    I love what you guys are doing for the sails community

Comments are closed.