Skip to main content
Version: v3

Client Engine Quick Start - Node.js

This document helps you get up to speed on how to create a Client Engine project, a simple two-player rock-paper-scissors game that relies on the Multiplayer JavaScript SDK for its logic.

In this document, we'll first learn how to start the project locally, briefly try it out, and then deploy the project to the cloud. After that, we will introduce the detailed game logic and how to develop our own game in Developer Guide.

Start the project

Install command line tools

Please check the Installation section of the documentation of the command line tool to install the command line tool and execute the Login command to log in.

Create a project

Get the sample project from Github. Please use this project as your project base:

git clone https://github.com/leancloud/client-engine-nodejs-getting-started
cd client-engine-nodejs-getting-started

Add the application's App ID and other information to the project:

lean switch

In the first step for selecting an App, select the LeanCloud app that corresponds to your game. In the second step, when selecting the Cloud Engine group, you must select the _client-engine group, for which LeanCloud provides optimized maintenance and support specifically for the Client Engine, as shown here:

image

Running locally

First install the necessary dependencies in the current project's directory by executing the following command:

npm install

If the Data Storage service will also be used, execute the following command:

npm install leancloud-storage

Open the debug log when you start the application:

DEBUG=ClientEngine*,RPS*,Play lean up

If you do not need the debug log, you can start it directly with the following command:

lean up

After startup, open http://localhost:3000/ in your browser to check if the project started properly.

Visit the site

Experience the game

After the server-side project is started, if you want to experience the Demo game, you need to open two additional Client Sample Demo pages at the same time, and do the following configurations in these two pages:

Click Configs and enter the App ID, App Key, and server URL of the previous selected application into APP_ID, APP_KEY, and PLAY_SERVER:

# If your browser is already logged into LeanCloud, select the relevant app below and copy and paste the relevant information into Configs:
APP_ID: "your-app-id"
APP_KEY: "your-app-key"

Next, enter http://localhost:3000 in Client Engine Server. As shown in the figure:

image

Once the information is filled in, click Login to Play to start the game.

Client Code

If you want to see the detailed client code, you can visit Client Sample Code on github.

Deploying to the Cloud

To deploy to the staging environment, run the following command in the root directory:

lean deploy --staging

Log in to the LeanCloud console in a browser, bind a Cloud Engine domain (custom domains starting with stg- will be automatically bound to the staging environment), and then visit the corresponding URL to see the text indicating that the Client Engine server is running.

For other detailed deployment methods, please refer to Deployment in the command line tools documentation.

Your first Client Engine game

Next, please see the documentation Your First Client Engine Game for a step-by-step guide on how to develop a rock-paper-scissors game based on this initial project.