O'Reilly logo

Express.js Blueprints by Ben Augarten, Marc Kuo, Eric Lin, Aidha Shaikh, Fabiano Pereira Soriani, Geoffrey Tisserand, Chiqing Zhang, Kan Zhang

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a new game

Now that we have defined the data structure of our game, let's start with implementing the logic to create and persist a new game document in the database, all the while following Test-Driven Development practices.

In order to create a new game, we need to accept a POST to /create with your name in the POST body:

{ name: 'player1' }

There are a few things we should think about:

  • We need to return the board information to the user, and whether or not game creation was successful
  • We need to ensure the player can access the game they just created, so we must send them the boardId
  • In order for the player to identify themselves, we also need to ensure that we send them the p1Key, which will be needed for all future moves that Player One ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required