Write After End error in node.js webserver

NodeJS is a non-blocking async platform.

In your case,

netSocket.write(messages);

is an async method; therefore, netSocket.end() is called before write is complete.

The correct use would be:

netSocket.write(messages, function(err) { netSocket.end(); });

The second argument here is a callback function that will be called once the ‘write’ method finishes its job.

I would recommend you read/watch more about NodeJS, async styles and callbacks.

Here is a great place to start: https://www.youtube.com/watch?v=GJmFG4ffJZU

And of course, the NodeJS API docs regarding net sockets.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)