Good morning, i'm asking for your help for my project. I want to display rainbow six stats since this api: https://www.npmjs.com/package/rainbowsix-api-node
I created a server node and express, a react's front. My problem: my node server crash stops 3 time out of 5, he is not stable and and I noticed that the r6 server npm solicited works well during off-peak hours. I run the server with npm start but when i update my react app the server often stops and displays this
after several searches, I do not understand where the problem may come from ; thanks for your help !
Console return this:
Server is listening on port 5000
undefined:1
<!DOCTYPE html>
^
SyntaxError: Unexpected token < in JSON at position 0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node index`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
my back's code:
const RainbowSixApi = require('rainbowsix-api-node');
const express = require('express');
const app = express();
const port = 5000;
const statsRouter = require('./routes/stats');
const R6 = new RainbowSixApi();
//let username = '<username here>';
let platform = 'ps4';
app.get('/api/stats/:username', (req, res) => {
const username = req.params.username;
R6.stats(username, platform).then(response => {
res.send(response);
}).catch(error => {
console.error(error)
});
});
app.use('/api/stats', statsRouter)
app.listen(port, (err) => {
if (err) {
throw new Error('Erreur')
}
console.log(`Server is listening on port ${port}`);
});
My React Code
class Cards extends Component {
constructor(props) {
super(props);
this.state = {
statsArray: []
};
}
componentDidMount(){
const urls =
[
'/api/stats/username1',
'/api/stats/username2',
'/api/stats/username3',
'/api/stats/username4',
'/api/stats/username5',
]
let promiseArray = urls.map(url => axios.get(url).then(response => response.data).catch(error => { console.error(error) }));
Promise.all(promiseArray)
.then(statsArray => this.setState({ statsArray }))
}