Table of Contents
- NodeJS 18+ (>= v18.16.0)
It's recommended to install Node Version Manager to handle the NodeJS installation and keep alongside another NodeJS versions.
- axios: Promise based HTTP client for the browser and node.js.
- cors: NodeJS package for providing a Connect/Express middleware that can be used to enable CORS (Cross-origin resource sharing) with various options.
- dotenv: Zero-dependency module that loads environment variables from a .env file into process.env.
- express: Fast, unopinionated, minimalist web framework for NodeJS.
- sequelize: Easy-to-use and promise-based NodeJS ORM tool for Postgres, MySQL, MariaDB, SQLite, DB2, Microsoft SQL Server, and Snowflake.
- sqlite3: Asynchronous, non-blocking SQLite3 bindings for Node.js..
- @types/cors: Type definitions for cors.
- @types/express: Type definitions for express.
- nodemon: Tool that helps develop NodeJS based applications by automatically restarting the node application when file changes in the directory are detected.
- ts-node: TypeScript execution and REPL for NodeJS, with source map and native ESM support.
After NodeJS installation you can verify the correct version opening a command prompt and enter the following:
$ node –v
Then you can run
$ npm install
to download the NodeJS modules.
Then create a .env
file at the same level (alongside) than the file package.json with the PORT
number to run the server locally
// Server port
PORT = 2020
Later perform the command
$ npm run dev
to start the server (for dev purposes).
The server has 3 endpoints.
PROD => baseUrl: https://melichallengebecupon-production.up.railway.app
DEV (LOCAL) => baseUrl: http://localhost:{PORT}
The first of all is the root of url to test if server is running (ping):
GET {baseUrl}/
it can respond with:
{
"msg": "it is alive"
}
The second endpoint is for send a list of favorites items and an amount, to select as many items as possible:
POST {baseUrl}/api/coupon/
with body
{
"item_ids": ["MCO805528860", "MCO651764055", "MCO960661151", "MCO896227961", "MCO1220007348", "MCO839432192", "MCO593417993", "MCO940922159", "MCO648550090", "MCO605845408"],
"amount": 500000
}
it can respond with:
{
"item_ids": [
"MCO605845408",
"MCO960661151",
"MCO896227961",
"MCO940922159",
"MCO593417993",
"MCO839432192"
],
"total": 449612
}
The third endpoint is to get the Top 5 of favorite items of all person want (based in multiple entries of previous endpoint)
GET {baseUrl}/api/coupon/
it can respond with:
[
{
"MCO605845408": 108
},
{
"MCO593417993": 78
},
{
"MCO839432192": 55
},
{
"MCO651764055": 21
},
{
"MCO805528860": 16
}
]