Skip to content

Commit 49eae8f

Browse files
sjvanschgeo
andauthored
Examples for Node server events (#1777)
Co-authored-by: Christian Georgi <[email protected]>
1 parent e113301 commit 49eae8f

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

node.js/cds-server.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,32 @@ cds.on('bootstrap', app => {
178178

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

181+
```js twoslash
182+
// @noErrors
183+
const cds = require('@sap/cds')
184+
cds.on('loaded', model => { /* ... */ })
185+
```
181186

182187

183188
### connect {.event}
184189

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

187-
192+
```js twoslash
193+
// @noErrors
194+
const cds = require('@sap/cds')
195+
cds.on('connect', service => { /* ... */ })
196+
```
188197

189198
### serving {.event}
190199

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

193-
202+
```js twoslash
203+
// @noErrors
204+
const cds = require('@sap/cds')
205+
cds.on('serving', service => { /* ... */ })
206+
```
194207

195208
### served {.event}
196209

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

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

229+
```js twoslash
230+
// @noErrors
231+
const cds = require('@sap/cds')
232+
cds.on('listening', ({ server, url }) => { /* ... */ })
233+
```
216234

217235

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

222240
This event supports _asynchronous_ event handlers.
223241

242+
```js twoslash
243+
// @noErrors
244+
const cds = require('@sap/cds')
245+
cds.on('shutdown', async () => { /* ... */ })
246+
```
224247

225248

226249

0 commit comments

Comments
 (0)