Services in FeathersJS are used for -

  1. Reading and/or Writing from Databases.
  2. Calling another API
  3. Calling other services like, sending a mail or processing a payment, etc.

For reading and writing from a database, we have service methods that allow us to perform CRUD operations in the database. The various service methods available to us are -

  1. FIND - Used to retrieve all of the data
  2. GET - Used to retrieve only specific entries
  3. CREATE - Used to create new data
  4. UPDATE - Used to update existing data by completely replacing all of it
  5. PATCH - Used to update existing data by only replacing the required columns or attributes
  6. REMOVE - Used to delete one or more existing entries

Creating a new Service

feathers generate service

The above command will generally create a service.js file, models.js file and a hooks.js file.

Models are where we define our database schema and the relationships between two different models.

When a new service is created, by default the models.js file will have a default model with just one attribute or column, named 'text'.

Hooks is where we write middleware functions, which can be invoked before or after or when an error occurs when calling an API.

In Part - 4 of the series, we shall see how to create & define a database schema as models in our service. So stay tuned, keep reading, and let me know what you think about the above article in the comment section below.