We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Connect

Let's scaffold the Peril project! Fork and then clone starter code from GitHub and move it somewhere on your machine. We will use this project for the rest of the course.

The starter code contains a few interesting things

  • The src/internal/gamelogic directory which contains the game logic modules for the Peril game.
  • src/internal/routing/routing.ts which contains some routing constants for the game.
  • Stubs of src/client/index.ts and src/server/index.ts, which are entry point scripts that run the client and server for the game.
  • The rabbit.sh script for starting and stopping RabbitMQ with Docker. For convenience, there are wrappers around this script in package.json so that you can run:
    • npm run rabbit:start to start RabbitMQ
    • npm run rabbit:stop to stop it
    • npm run rabbit:logs to view the server logs

Assignment

npm install amqplib
import amqp from "amqplib";
     async function main() {
         const rabbitConnString = "amqp://guest:guest@localhost:5672/";
         const conn = await amqp.connect(rabbitConnString);
         ...
    

To test your code, use the script to start a RabbitMQ server with Docker in the background:

npm run rabbit:start

Once it's running, open a new terminal and run your server:

npm run server

You should see your message that the connection was successful. Press Ctrl+C to exit the program and see the shutdown message.