'express cant handle too many requests?

Im currently working on my new MERN stack project. Im trying to get information about time spent on every location and everything seemed ok until i' ve discovered a bug. After changing location and sending post request to server about 10 times whole localhost server is frozing. Any calls to the server stop working. This is very frustrating and i cant figure it out. Do you guys have any ideas?

UseEffect calling action:

    useEffect(() => {

     dispatch(savePageStats())
}, [location])

Redux action call:

export const savePageStats = () => async (dispatch) => {
try{
    const arr = []
    await api.savePageSession(arr)    
}catch(err){
    console.log(err)
}

Axios api:

export const savePageSession = (arr) => API.post('/stats/savepagesession', arr)

Express router:

    const app = express()
app.use(bodyParser.json({ limit: '30mb', extended: true}))
app.use(bodyParser.urlencoded({ limit: '30mb', extended: true}))
app.use(cors())
app.use('/users', usersRoutes)
app.use('/messages', messagesRoutes)
app.use('/stats', statsRouter)

dotenv.config()
mongoose.connect(process.env.CONNECTION_URL)
.then(() => app.listen(process.env.PORT, () => console.log(`server running on port ${process.env.PORT}`) ))
.catch((err) => console.log(err))

Express controler

export const savePageSession = async (req, res) => {
try{
   
    console.log('im here')
    
}catch(err){
    res.status(500).json({message: 'something went wrong'})
}

}



Solution 1:[1]

The savePageSession route handler doesn't send any response back to the client. That means the browser will still be waiting for a response and will eventually stop sending requests to your server until the previous requests finish or eventually timeout.

Add at least something simple like res.send("ok"); to the route. All http request handlers on your server MUST send some kind of response back to the client or it will mess up the client.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1