1

In my node express js project I am running a http server (i.e... http.createServer(app)).. (uisng bodyParser, morgan, serve-favicon, express-jwt middilwares).. When the user select any line in the command prompt (using mouse, Command title also prefixed with the word "Select"), the express http server is not serving any further request until i hit an enter(return key) to cancel/finish the selection.

I am not using any "readline" module...

Anyone Please share me your view on this issues..

Karthikeyan
  • 406
  • 3
  • 14

1 Answers1

2

IMHO, it is probably because the I/O of the command prompt (console ?) aren't asynchronous. You need to handle the asynchronous way to do what you want to do in node. It means that parts of the code are (probably) blocking.

Some explanations here on another SO post about that. According to the documentation about the console here "it should be a very rare occurrence indeed that a write blocks, but it is possible."

As Node is made with low level C, it is possible that the system waits for a validate, after you start to write something in the command prompt.

I had a similar problem with logs.

Community
  • 1
  • 1
Aethyn
  • 695
  • 1
  • 4
  • 16
  • 1
    If you're trying to make a sort of "database query" system, maybe it's better to not use the command prompt and prefer an ORM (like Sequelize for example if it's SQL). You will be able to make a basic database connection wrapper, and simply execute the query (some Selects ?) as a parameter of a secured function. You have some nice tutorials with MongoDB, [this is a very good one](https://scotch.io/tutorials/build-a-restful-api-using-node-and-express-4). – Aethyn Apr 01 '16 at 13:39