- Live Demo Here
- Read about Using the server (Hitting the endpoints)
- Why this project ?
- Project description
- Scripts
- Project structure
- Server configuration
- Before using the server
- Using the server (Hitting the endpoints)
- Last Note
I built this project as part of an assignement to apply for a Fullstack position.
- The project is to create a simple server that manages a parking lot that is rate-limited by the IP Address.
- The only allowed packages are
express
with Node.js anddotenv
, apart from this it's forbidden to use any other libraries or databases. - 3 main endpoints should be created which are :
- Park a Car: The Endpoint will be given the car number as input and outputs the slot where it is parked. If the parking lot is full, the appropriate error message is returned.
- Unpark the Car: This endpoint takes the slot number from which the car is to be removed from and frees that slot up to be used by other cars.
- Get the Car/Slot Information: This endpoint can take either the slot number or car number and return both the car number and slot number for the input.
- Apart from this, the server will rate-limit the number of requests coming in. So, if a user makes more than 10 requests in 10 seconds, we return the appropriate error message.
- Important Note: Implement OWN rate limiter without using any third party library.
npm install
: install dependenciesnpm run postinstall
: after installing the dependencies, compile the project Typescriptsrc/
folder to Javascriptdist/
foldernpm start
: start the servernpm run devserver
: start the server in dev mode (restart the server on each save)npm run test
: run unit and integration tests
src/
: Typescript source folderapi/
: folder containing the RESTful API routeshelpers/
: folder containing code and functionality to be shared by different parts of the projectmiddlewares/
: folder containing Express middlewares which process the incoming requests before handling them down to the routes, currently holds the Rate Limiter middlewaremodels/
: folder containing Parking Lot Singleton Model, ensures that the same instance of the the Parking Lot class is used accross the projecttests/
: folder containing unit and integration tests, used to test the code in other foldersserver.js
: file that initialize the server and glues everything together
.env
: file holding the parking lot size variable, has to be positive and non null numberjest.config.js
: jest config file for Typescript supporttsconfig.json
: Typescript config filepackage.json
: file that remembers all packages that the server depends on and their versions
PARKING_LOT_SIZE
variable in.env
file : input a positive non null number to create a parking lot size of your choice, initialized to 4WINDOW_SIZE_IN_SECONDS
andMAX_WINDOW_REQUEST_COUNT
constants inmiddlewares/rateLimiter.js
: controls how many requests (MAX_WINDOW_REQUEST_COUNT
) can be done within the time (in seconds) defined inWINDOW_SIZE_IN_SECONDS
, initialized to 10 requests possible per 10 seconds
run npm install
to install dependencies
Since any database usage isn't allowed, the storage of information is volatile, so all information is stored only while the server is running, the data is lost when restarting the server
make sure to follow these conventions:
PARKING_LOT_SIZE
variable in.env
file : input a positive non null number to create a parking lot size of your choice, otherwise an error is thrown and the server will not startcarId
: a valid car ID is defined to start with the stringcar_
followed by a positive number- invalid car IDs examples :
c
|1
|car
|car_
|car_-1
|car_1a
|car_aa
- valid car IDs examples :
car_0
|car_00
|car_00000
|car_1
|car_01
|car_45
|car_004500
| ...
- invalid car IDs examples :
slotId
: a valid slot ID is defined to start with the stringslot_
followed by a positive non null number- invalid slot IDs examples :
s
|1
|slot
|slot_
|slot_-1
|slot_0
|slot_1a
|slot_aa
- valid slot IDs examples :
slot_1
|slot_2
|slot_3
| ... |slot_50
| ...
- invalid slot IDs examples :
run npm start
to launch the server, make sure to give the PARKING_LOT_SIZE
variable in .env
file a positive non null number
GET and PUT HTTP methods are the only methods used in the project
The server has 4 main usable routes :
- GET
/
: returns in json format the actual state of the parking lot - PUT
/api/parkcar/:carId
: with a given valid car ID, park the car and return the appropriate message, or return the appropriate error message - PUT
/api/unparkcar/:slotId
: with a given valid slot ID, unpark the car, free up space and return the appropriate message, or return the appropriate error message - GET
/api/getcarslotinformation/:id
: with a given valid car ID or valid slot ID, return the parking slot information, or return the appropriate error message
Built with <3 and excitement by Salim Dellali