Ask coding questions

← Back to all posts
How to make a global leaderboard with javascript?
MikeJMS8910 (160)

So in my game, I want to have a leaderboard of all of the users and show who has the most of each stats. So how would I be able to do this?

Comments
hotnewtop
notGilbert (121)

You'll need a server - you can use a python / nodejs repl for that

  1. Use HTTP requests to make updates to the leaderboard from your main game site.
  2. You'll probably want a database (you can use replit's built in one) to store the leaderboard stats.
MikeJMS8910 (160)

@notGilbert I am using javascript and repl database isn't supported by that. But I already have a saving function and I am using cookies. Can you give me documentation for how to set up the HTTP request and the servers?

notGilbert (121)

@MikeJMS8910 replit database does support (have a library) for javascript, just not on the client-side.

If you're familiar with javascript, use a Nodejs repl as the server. I like express, a library for handling HTTP requests.

A server is a computer (program) that handles requests and "serves" files, it has connection to the database. A client should not have a direct connection to the database (anyone would be able to modify the data; its stupid). A server / client can communicate with the other using HTTP requests.

vocabulary
Client - what the user sees, your game

Server - a computer (program) that provides information to the client. It handles things like user authentication, and storing data. Users don't see this.

HTTP requests - a protocol used to structure requests over the internet. It is used for the client and server to communicate.

=====

express on codeacademy, part one should be enough
HTTP requests explanation
express js website

MikeJMS8910 (160)

@notGilbert Thanks ill need to check these links out later