Project Link: Pokemon Infinite Fusion Calculator
I am a beginner web developer and I have just started learning back-end development. I am currently working on a unique project called Pokemon Infinite Fusion Calculator. For this tool, I need to develop an API that retrieves fusion sprite data and sends it in the response.
I have a large JSON file (74MB+) that contains data on fused Pokemon sprites. Each entry in this file uses a key representing the fusion dex number. For example, the fusion of Charizard (6) and Porygon-Z (275) is represented by Charion-Z (6.275) and Porygzard (275.6), with the corresponding data and this is api code
const fs = require('fs');
const path = require('path');
const express = require('express');
const app = express();
// Load JSON data into memory
const dataFilePath = path.join(__dirname, 'data.json');
const jsonData = JSON.parse(fs.readFileSync(dataFilePath, 'utf8'));
// In-memory data store
const dataStore = new Map();
for (const [key, value] of Object.entries(jsonData)) {
dataStore.set(key, value);
}
// API endpoint to get fusion data
app.get('/api/fusion/:dexId', (req, res) => {
const dexId = req.params.dexId;
// Get data from the in-memory data store
const data = dataStore.get(dexId);
if (data) {
res.json(data);
} else {
res.status(404).json({ error: 'DexId not found' });
}
});
// Start server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
I am receiving over 30,000 API requests daily, and my server cost is approximately $0.50 per day. I would like to know how I can make this response faster and reduce resource consumption.
Thank you!
Infinite Fusion is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.