Running a local server with javascript


I want to create a simple Javascript program with a HTML interface. The program will run in Chrome. I will also use node-serialport and Node.js to comunicate with an Arduino. I have a HTML and JavaScript file done, but I have no clue how to run it, or how to implement Node.js or node-serialport, nor how to "start" the sever. Initially it will only be running locally, but eventually it may become a real sever. For now, how do I run all that locally?

EDIT: I'm using the sample code from, with the CoffeeScript converted into JavaScript.

6/17/2012 4:36:15 AM

Accepted Answer

Lucas, glad you found the blog post useful; perhaps I should add this information to it.

Getting the sketch into your Arduino

Just fire up the Arduino application, paste in the sketch code, and hit "Upload." Should be all you need to do here.

Starting the Node.js Server

What operating system are you using this on? Finding out how to access your Arduino microcontroller via node-serialport will differ based on your OS.

In the source code, change the string value of port to be your Arduino's device (once you know it). Also, the script depends on Express and (of course) node-serialport from NPM, so run npm install express serialport in the directory where your JavaScript file is saved. Finally, run the file with node server.js (assuming server.js is the name of your file). Then you can access the server at http://localhost:8080.

6/17/2012 8:36:18 AM

You can use node.js to serve up HTML with Express. If your main Javascript file is called server.js, then run it by typing:

node server.js

at the command line.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow