Skip to main content
Don't put the answer in the question; You can self-answer your question if you found the solution
Source Link
Rizier123
  • 59.8k
  • 17
  • 106
  • 167

Node.JS Buffer has a newline after it -SOLVED-

How do I remove the newline from this code:?

 socket.on('data', function(data){   console.log('Data in server, sending to handle()');   worker.handle(data, socket);  }); 

Worker.handle():

 exports.handle = function handle(command, socket) {  console.log('Data sent to handle()');  command = command.toString(); console.log(command); 

? Any help will be very appreciated! console.log(command);

Edit: 

I am getting this output: test data [newline]

test data [newline] 

Edit 2: Here

Here is the continuing code:

 if (command === 'look') {   // stuff  }  if (command === 'login') {   // stuff 

Edit 3: I solved it myself with

worker.handle(data.replace(/[\n\r]/g, ''), socket); 

Node.JS Buffer has a newline after it -SOLVED-

How do I remove the newline from this code:

 socket.on('data', function(data){   console.log('Data in server, sending to handle()');   worker.handle(data, socket);  }); 

Worker.handle():

 exports.handle = function handle(command, socket) {  console.log('Data sent to handle()');  command = command.toString(); console.log(command); 

? Any help will be very appreciated!

Edit: I am getting this output: test data [newline]

Edit 2: Here is the continuing code:

 if (command === 'look') {   // stuff  }  if (command === 'login') {   // stuff 

Edit 3: I solved it myself with

worker.handle(data.replace(/[\n\r]/g, ''), socket); 

Node.JS Buffer has a newline after it

How do I remove the newline from this code?

socket.on('data', function(data){ console.log('Data in server, sending to handle()'); worker.handle(data, socket); }); 

Worker.handle():

exports.handle = function handle(command, socket) { console.log('Data sent to handle()'); command = command.toString(); 

console.log(command);

Edit: 

I am getting this output:

test data [newline] 

Edit 2:

Here is the continuing code:

if (command === 'look') { //stuff } if (command === 'login') { //stuff 
added 94 characters in body; edited title
Source Link
whiskers75
  • 197
  • 2
  • 9

Node.JS Buffer has a newline after it -SOLVED-

How do I remove the newline from this code:

 socket.on('data', function(data){ console.log('Data in server, sending to handle()'); worker.handle(data, socket); }); 

Worker.handle():

 exports.handle = function handle(command, socket) { console.log('Data sent to handle()'); command = command.toString(); console.log(command); 

? Any help will be very appreciated!

Edit: I am getting this output: test data [newline]

Edit 2: Here is the continuing code:

 if (command === 'look') { // stuff } if (command === 'login') { // stuff 

Edit 3: I solved it myself with

worker.handle(data.replace(/[\n\r]/g, ''), socket); 

Node.JS Buffer has a newline after it

How do I remove the newline from this code:

 socket.on('data', function(data){ console.log('Data in server, sending to handle()'); worker.handle(data, socket); }); 

Worker.handle():

 exports.handle = function handle(command, socket) { console.log('Data sent to handle()'); command = command.toString(); console.log(command); 

? Any help will be very appreciated!

Edit: I am getting this output: test data [newline]

Edit 2: Here is the continuing code:

 if (command === 'look') { // stuff } if (command === 'login') { // stuff 

Node.JS Buffer has a newline after it -SOLVED-

How do I remove the newline from this code:

 socket.on('data', function(data){ console.log('Data in server, sending to handle()'); worker.handle(data, socket); }); 

Worker.handle():

 exports.handle = function handle(command, socket) { console.log('Data sent to handle()'); command = command.toString(); console.log(command); 

? Any help will be very appreciated!

Edit: I am getting this output: test data [newline]

Edit 2: Here is the continuing code:

 if (command === 'look') { // stuff } if (command === 'login') { // stuff 

Edit 3: I solved it myself with

worker.handle(data.replace(/[\n\r]/g, ''), socket); 
added 189 characters in body
Source Link
whiskers75
  • 197
  • 2
  • 9

How do I remove the newline from this code:

 socket.on('data', function(data){ console.log('Data in server, sending to handle()'); worker.handle(data, socket); }); 

Worker.handle():

 exports.handle = function handle(command, socket) { console.log('Data sent to handle()'); command = command.toString(); console.log(command); 

? Any help will be very appreciated!

Edit: I am getting this output: test data [newline]

Edit 2: Here is the continuing code:

 if (command === 'look') { // stuff } if (command === 'login') { // stuff 

How do I remove the newline from this code:

 socket.on('data', function(data){ console.log('Data in server, sending to handle()'); worker.handle(data, socket); }); 

Worker.handle():

 exports.handle = function handle(command, socket) { console.log('Data sent to handle()'); command = command.toString(); console.log(command); 

? Any help will be very appreciated!

Edit: I am getting this output: test data [newline]

How do I remove the newline from this code:

 socket.on('data', function(data){ console.log('Data in server, sending to handle()'); worker.handle(data, socket); }); 

Worker.handle():

 exports.handle = function handle(command, socket) { console.log('Data sent to handle()'); command = command.toString(); console.log(command); 

? Any help will be very appreciated!

Edit: I am getting this output: test data [newline]

Edit 2: Here is the continuing code:

 if (command === 'look') { // stuff } if (command === 'login') { // stuff 
added 80 characters in body
Source Link
whiskers75
  • 197
  • 2
  • 9
Loading
added 36 characters in body
Source Link
whiskers75
  • 197
  • 2
  • 9
Loading
Source Link
whiskers75
  • 197
  • 2
  • 9
Loading