Skip to content

Commit ad614f1

Browse files
[Issue 12622] Node.js guide - update example code (docker#15922)
* update server.js code
1 parent 8ebd41f commit ad614f1

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

language/nodejs/develop.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,30 @@ $ docker run -it --rm -d -v mongodb:/data/db \
5050
Okay, now that we have a running MongoDB, let’s update `server.js` to use MongoDB and not an in-memory data store.
5151

5252
```javascript
53-
const ronin = require( 'ronin-server' )
54-
const mocks = require( 'ronin-mocks' )
53+
const ronin = require( 'ronin-server' )
5554
const database = require( 'ronin-database' )
56-
const server = ronin.server()
55+
const mocks = require( 'ronin-mocks' )
5756

58-
database.connect( process.env.CONNECTIONSTRING )
59-
server.use( '/', mocks.server( server.Router(), false, false ) )
60-
server.start()
57+
async function main() {
58+
59+
try {
60+
await database.connect( process.env.CONNECTIONSTRING )
61+
62+
const server = ronin.server({
63+
port: process.env.SERVER_PORT
64+
})
65+
66+
server.use( '/', mocks.server( server.Router()) )
67+
68+
const result = await server.start()
69+
console.info( result )
70+
71+
} catch( error ) {
72+
console.error( error )
73+
}
74+
}
75+
76+
main()
6177
```
6278

6379
We’ve added the `ronin-database` module and we updated the code to connect to the database and set the in-memory flag to false. We now need to rebuild our image so it contains our changes.

0 commit comments

Comments
 (0)