M
M
Maxim Sokhryakov2018-07-31 22:34:43
Node.js
Maxim Sokhryakov, 2018-07-31 22:34:43

Why does Node.js freeze?

In short: after trying to add session storage to MongoDB, when a page is requested from the server, the server does not respond to the request, and the page load turns into an endless spectacle of the loading icon. If you interrupt the download, GET /vacations appears in the server console log - - ms - -
To be more specific:
Project code https://github.com/Ortum/myNotes ,
create-session branch, commit commit
63125a69327cb4cf18641d37649ce22812560bc1 previous, before top)
Learning express from Ethan Brown's 2017 book on Express.
In the book, the implementation of session storage in mongodb is implemented through the session-mongoose module.
Since I am using express.js version 4.xx, this solution is no longer possible, due to version incompatibility ( proof from session-mongoose plugin github ).
And I decided to do it in an oak (or maybe not) way.
Connected express_session = require('express-session') , ​​then require('connect-mongo')(express_session); .
Then I started connecting to mongodb: ( file app.js lines 139 - 148 ) ps I don’t paste the code here, because of the crooked formatting (if someone tells me how to do it beautifully, I will be grateful)
I note that this is the second connection to the database, the first on line 59, mongoose.connect(dbconfig.database, opt);
User data, such as username and password, has been moved out of the repository.
If you remove everything related to the session, then the server starts and accepts and processes requests without any problems.
When sessioning is enabled, the server endlessly ponders the request.
pss I'm sorry in advance to forgive me that all path handlers are in app.js, and not in their native routes/*.js
psss I can't even imagine how you can approach the formulation of the question to find something similar on the Internet, and I'm a little desperate

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-07-31
@maximsohryakov

Suspicious piece of code:

app.use(function(req, res, next) {
  req.session.number =req.session.number + 1 || 1;
})

There must be a call to next somewhere, right?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question