Search code examples
feathersjs

How to use a service only to process and not store in the FeathersJS


How do I create a service that does only one processing, without registering in the database. An example: sending any data it does a processing using a hook and returns the result.

Here it works more the return is the answer of the data in the database, I do not care to store

app.use('/process', createService(options)); 

I tried something like this but got an error. Sorry, I am new to it.

app.use('/process', function(req, res) {

});

Solution

  • This is explained in detail in the Basics guide of the FeathersJS documentation, specifically the services section. The API documentation can be found here. A service is any object or class that implements one or more of the following methods which can do pretty much anything:

    class MyService {
      async find(params) {
        return [];
      }
      async get(id, params) {}
      async create(data, params) {}
      async update(id, data, params) {}
      async patch(id, data, params) {}
      async remove(id, params) {}
      setup(app, path) {}
    }
    
    app.use('/my-service', new MyService());
    

    A custom service can be generated with the CLI via feathers generate service and choosing the "A custom service" option. It can then be edited in src/services/<name>/<name>.class.js.