3

Very New to Node.js...

I am working on reading a barcode from a COM Port of a R232 Barcode Scanner.
I have found a Node.js call serialport and installed it. I can successfully read the barcode scan, from within a node.js command window, using the example from the installation.

My next step is to see if I can integrate this barcode scan within my ASP.net Web Forms application. I am hosting my application in IIS not looking to change that. Also trying to avoid using ActieX or Java Applets or Silverlight. Also trying to keep it browser based vs native Windows Desktop Application. At the moment don't have the time to convert to Asp.Net MVC.

This is now where I am confused.

1) Node.js can create its own web server and serve its own html content without the need of IIS. So that leads me to believe these two technologies cannot co-exist within the same project/web server instance. Is this true?

2) What I want to do is in the javascript of my Web Forms Application, make the call to read the serial port and populate an input textbox with the results. I don't want to start piecing this together if this is not possible, and I don't think it is. Looking for verification on my hypothesis.

e.g.

<!-- HTML FORM -->    
<input type="textbox" id="txtBarcode" />


<!-- Javascript Section -->
<!-- Bind some event for the input textbox -->
<script>

   function ReadScan(){
   var com = require("serialport");

   var serialPort = new com.SerialPort("COM4", {
       baudrate: 9600,
       parser: com.parsers.readline('\r\n')
     });

   serialPort.on('open',function() {
     console.log('Port open');
   });

   serialPort.on('data', function(data) {
      //I don't think will work here....
     $('#txtBarcode').val(data);
   });
}


</script>

3) I think what I am trying to do is treat node.js as just another web Javascript library like knockout.js or jQuery. Can I treat Node.js this way or no?

0

2 Answers 2

2

Node.js can create its own web server and serve its own html content without the need of IIS.

Yes.

So that leads me to believe these two technologies cannot co-exist within the same project/web server instance. Is this true?

No.

You can use Node to generate content without it running a web server. e.g. you could write something that confirms to the CGI specification. (This would be pretty inefficient and I wouldn't recommend it, but it is possible).

You can run a webserver with Node on a different port and then proxy requests to it from IIS.

I think what I am trying to do is treat node.js as just another web Javascript library like knockout.js or jQuery. Can I treat Node.js this way or no?

No.

Node.js is a program that executes JavaScript. It isn't a library written in JavaScript.

Even if it was, if you could use it like Knockout or jQuery then it would run inside the browser and not have access to the serial ports connected to the server (or to those connected to the computer running the browser, since JS in the browser is heavily sandboxed).

I am working on reading a barcode from a COM Port of a R232 Barcode Scanner.

What I want to do is in the javascript of my Web Forms Application, make the call to read the serial port and populate an input textbox with the results

For that to make sense, you'll need to have the bar code reader connected to the computer running the browser.

That sort of hardware usually operates by emulating a keyboard. You should be able to install its standard keyboard driver, put the focus on the input in the web page and just start using it. No programming needed.

(Optional programming: Writing client side JS to recognise when the input has been populated and submit the form automatically).

Sign up to request clarification or add additional context in comments.

3 Comments

This is where the disconnect is between our hardware team and dev team. The scanner will not work in notepad, because it is reading via com port. So in order to get it to work in notepad as a regular keyboard, we would need to purchase different barcode scanners.
The scanner would be connected to the computer running the browser. As I have found other solutions using WCF services and such read from the Server's com port. I found Node to be useful in that it ran server side related code from the client.
"I found Node to be useful in that it ran server side related code from the client" — It doesn't. It runs JavaScript code. If you run it as a server, that's server side code as server side code. If you write a client in it (not compatible with a browser) then it runs client side code as a client.
1

No, you cannot treat nodejs as just another JavaScript library as nodejs is NOT a library but an application, in the same way that a browser is an application ( that also happens to implement javascript ). Both nodejs, and browsers extend the JavaScript language. In some cases ( like console.log ), they implement equivalent functionality. But "require", for example, is an example of a nodejs extension to the JavaScript language, which I believe has not been implemented on browsers.

A lot of the extensions of nodejs are exactly to deal with files and lower level OS hooks, exactly because you need that for servers. Browsers (clients ) usually want to avoid that type of access ( for security ).

You may want to look into building a nodejs based app with something like the Github Electron project, which basically packages the nodejs app and your code into a stand alone app.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.