Skip to content

Examples for Node server events #1777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions node.js/cds-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,32 @@ cds.on('bootstrap', app => {

Emitted whenever a CDS model got loaded using `cds.load()`

```js twoslash
// @noErrors
const cds = require('@sap/cds')
cds.on('loaded', model => { /* ... */ })
```


### connect {.event}

Emitted for each service constructed through [`cds.connect`](cds-connect).


```js twoslash
// @noErrors
const cds = require('@sap/cds')
cds.on('connect', service => { /* ... */ })
```

### serving {.event}

Emitted for each service constructed by [`cds.serve`](cds-serve).


```js twoslash
// @noErrors
const cds = require('@sap/cds')
cds.on('serving', service => { /* ... */ })
```

### served {.event}

Expand All @@ -199,7 +212,7 @@ A one-time event, emitted when all services have been bootstrapped and added to
```js twoslash
// @noErrors
const cds = require('@sap/cds')
cds.on('served', (services)=>{
cds.on('served', async (services) => {
// We can savely access service instances through the provided argument:
const { CatalogService, db } = services
// ...
Expand All @@ -213,6 +226,11 @@ This event supports _asynchronous_ event handlers.

A one-time event, emitted when the server has been started and is listening to incoming requests.

```js twoslash
// @noErrors
const cds = require('@sap/cds')
cds.on('listening', ({ server, url }) => { /* ... */ })
```


### shutdown {.event}
Expand All @@ -221,6 +239,11 @@ A one-time event, emitted when the server is closed and/or the process finishes.

This event supports _asynchronous_ event handlers.

```js twoslash
// @noErrors
const cds = require('@sap/cds')
cds.on('shutdown', async () => { /* ... */ })
```



Expand Down