I want to use feathersJS for a project. I have gone through the documentation and also tried to go through the chat app available on documentation but still, I have not got it well.
As I understood for each functionality they create service and database, for example for user and message, there are two services have created which use Nedb database.
My question is, should I create services which contain a database for every functionality am going to implement? second, for every service created by feathers there app.js, so the logic code I want writes other than what created by feathersJS needs be written on app.js or need to create another app.js by myself?
I would also appreciate if you could suggest me some projects done by using feathersJS.
Are you using the CLI to create the application and services? Maybe will be easier. But actually is not necessary to create a database for every service, except if is really necessary to use more than 1.
About the logic codes, it depends. It can be handled as a express middleware or in the service hooks (for every service or for the application). This second case is more about pre and post processing the client request. Of course, the operation made itself can be a class, a function or even an API call. For example, you can check a param sent by client in the request only before to execute the 'get' operation adding the ckeck into GET before hook. Also have a hook to check the authentication.
//in other some place
module.exports = (hook) => {
return hook.params.query.device_type === 'smartphone'
? console.log('is a smartphone request')
: console.log('is not a smartphone request');
}
//src/services/devices/devices.hooks.js
const { authenticate } = require('@feathersjs/authentication').hooks;
const myVerification = require('path/to/myverification');
const myVerification2 = require('path/to/myverification2');
module.exports = {
before: {
all: [ authenticate('jwt') ],
find: [],
get: [myVerification, myVerification2],
create: [],
update: [],
patch: [],
remove: []
},
after: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
},
error: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
}
};