Wednesday, 25 April 2018

Simple server causing Max Listener warnings in console

I have the following server code ( sans imports and some process info )app.use(express.static(__dirname)) app.use(bodyParser.json()) app.use(form()) app.post('/api', (req, res) => { db.posts.push(Object.assign({ submitted_on: Date.now() }, req.fields)) res.json({ data: { id: db.posts.length - 1 } }) }) app.get('/api', (req, res) => { if (req.query.id) { return res.json({ data: db.posts[req.query.id] }) } return res.json({ data: db.posts }) }) app.listen(5000, () => console.log('Hello!')) When I start this server and go to index.html, everything is great. However, after a few minutes, I get a max listener. You should increase it warning printed in the console.What would cause a single client cause the max listeners issue with the above code? Am I doing something wrong with this simple server?

Submitted April 25, 2018 at 06:58PM by cirsca

No comments:

Post a Comment