As most standard tasks and use cases are covered by generic service providers, the need to add service implementation code is greatly reduced and minified.
The remaining cases reduce to real custom logic, specific to your domain and application, such as domain-specific programmatic validations.
As an example, let's program a validation that ensures that the date of birth passed is before the date of death passed when creating a new author via the AdminService.
The easiest way to add custom service implementations is to simply place an equally named .js file next to the .cds file containing the respective service definition. I.e. in our case we place a file named admin-service.js in the srv folder of our project, as this folder also contains the file admin-service.cds, which is used to define the AdminService (see following figure).

Note
Alternatively, you can also annotate the service definition in the.cds
file with the @impl
annotation. You use this annotation to explicitly refer to another .js
file that should contain the service implementation.There are different ways to implement the required custom logic in the .js file. The most common way is to use a subclass of cds.ApplicationService to benefit from generic out-of-the-box implementations. This is because the cds.ApplicationService class is the default service provider implementation, which adds the generic providers already discussed to a service definition.
To create a subclass of cds.ApplicationService, we first assign the @sap/cds module to the constant cds in our code (line 1). The @sap/cds module is the cds facade object that provides access to all CAP Node.js APIs.
We then create a subclass of cds.ApplicationService in lines 4 to 6, in which we will later implement our custom logic. The name of the subclass is arbitrary. We call it here like our service interface, i.e. AdminService.
In line 9, we make the AdminService class available for import into other modules. This is common practice in Node.js to structure code.
Note
If you now start the application by entering cds watch
in the terminal, the added service implementation file is displayed in the log via an output similar to the following: