Skip to content

Commit

Permalink
move mongodb and firebase deps to devDependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolodavis committed Jul 28, 2018
1 parent 9fa814c commit 6a8b657
Show file tree
Hide file tree
Showing 4 changed files with 283 additions and 82 deletions.
12 changes: 7 additions & 5 deletions docs/multiplayer.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,13 @@ $ npx babel-node --presets zero src/server.js
Navigate to http://localhost:8000/
```

#### Database
#### Storage

The default storage implementation is an in-memory map. However,
you can provide your own adapter to connect to any backend, or
use the bundled MongoDB connector.
The default storage implementation is an in-memory map.
If you want something that's more persistent, you can use one
of the bundled connectors for various backends, or even implement
your own connector. For example, here is how you can keep your
game state in a MongoDB.

```js
const { Server, Mongo } = require('boardgame.io/server');
Expand All @@ -215,4 +217,4 @@ const server = Server({
server.run(8000);
```

!> You can get a free MongoDB instance at places like mlab.com.
See [here](storage.md) for more details about how to customize storage.
63 changes: 63 additions & 0 deletions docs/storage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Storage

The framework comes bundled with various connectors to different backends
depending on how you want to persist your game state.

### MongoDB

First, install the `mongodb` package:

```
npm install --save mongodb
```

Then modify your server spec to indicate that you want to connect to Mongo:

```js
const { Server, Mongo } = require('boardgame.io/server');
const { TicTacToe } = require('./game');

const server = Server({
games: [TicTacToe],

db: new Mongo({
url: 'mongodb://...',
dbname: 'bgio',
}),
});

server.run(8000);
```

!> You can get a free Mongo instance at places like [mLab](https://mlab.com/).

### Firebase

First, install the necessary packages:

```
npm install --save firebase
```

Then modify your server spec to indicate that you want to connect to Firebase:

```js
const { Server, Firebase } = require('boardgame.io/server');
const { TicTacToe } = require('./game');

const server = Server({
games: [TicTacToe],

db: new Firebase({
config: {
apiKey: '...',
authDomain: '...',
databaseURL: '...',
projectID: '...',
},
dbname: 'bgio',
}),
});

server.run(8000);
```

0 comments on commit 6a8b657

Please sign in to comment.