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 http://brandontilley.com/2012/03/02/controlling-an-arduino-from-nodejs.html, with the CoffeeScript converted into JavaScript.
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.
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.
Related
I am new to Nodejs world.I have some questions.Why the node service do not need to start while the apache service need to start when i use the command node xxx.js it can give me the result.How can the node do this?What are the steps of this process.
node is a program that contains the Javascript interpreter. To run a script file, you run node and pass it the script you want to run on command line. It initializes itself, then loads and runs the desired script.
node is more generic than Apache. It is not, by itself, a server of any kind. If you want a node.js app to be a server, you have to start a server yourself in your Javascript code.
Apache is a web server. When you start it, it starts a web server and then you can run things in the context of that web server. Apache does not contain it's own language interpreter like node does. It can run other types of code like PHP, but you have to supply it with a PHP interpreter in order for it to do that. node, on the other hand, has a Javascript interpreter built in.
While node can be used to create a web server by writing a Javascript script that creates and starts a web server, node is more generic than Apache. node can be used for all sorts of non-web server types of things. For example, I have a nodejs script on my computer that runs automatically each night that cleans up a bunch of automatic backup files on my disk by aging them (files older than a week are deleted). That isn't something you would do with Apache.
So, while there's some functionality overlap only because you can create a web server with node.js, node and Apache are fundamentally different types of tools.
I have implemented a nodejs server that serves incoming requests to use the bluetooth services of the local computer. I want the nodejs server to be packed as an windows executable file so that I can distribute it. People should be able to just install/run that .exe which will install any packages required (if any) and run the server. How to do this?. I saw and tried node-webkit etc., but they are UI-centric, that is it can pack a nodejs application that opens a html page. But I want my server javascript file to be executed, like the way it is done in command prompt : node file-name.js. How to do this?
I've a server running with nodejs and for execute this I use a .bat file.
Create a .bat file
Inside of the file put:
cd path/to/server/
node índex.js
I used JXCore for this task in the past. It basically creates one executable that includes everything.
Unfortunately active development of is halted.
Solution:
You can use nexe for that.
Create a single executable out of your node.js app
Motivation
Ability to run multiple applications with different node.js runtimes.
Distributable binaries without needing node / npm.
Starts faster.
Lockdown specific application versions, and easily rollback.
Faster deployments.
Total rookie question, however in my hours searching have not found a proper solution:
I have made a Node.js/express server using WebStorm IDE, tested it and run it successfully, however now that it is complete, I would like to be able to run it manually as a standalone project.
I have tried just running the www js file, which does start the server, however some functionality is lost, such as being unable to find and run a python script (not found).
My question is how do I fully transfer all the functionality incorporated in the WebStorm project so that server can be run outside of the IDE?
ADD: Currently only python scripts in the /bin directory will be found (server terminal run location)
I'm completely new to nodeJs, and just to learn step by step. I managed to download, run nodeJs via the CMD and tested by creating file, all works fine. The problem now is when I want to tell nodeJs to display the output on the browser instead. I simply followed the tutorial but I'm getting runtime error. I suspect the port is somewhat wrong. Which port no I should use here, is it my localhost port which is 80, I tried it to no avail.
Here's the error message:
Referred here:Using node.js as a simple web server
All I want is to be able to see the output in the browser via nodeJs. I think the port 9999 is meant for tcp connection as I'm learning for real-time app.
You're not using NodeJS to run your code. To run your code using NodeJS, run them with node:
node c:\projects\test\helloweb.js
The reason what you tried didn't work is that typing c:\projects\test\helloweb.js in cmd.exe and pressing Enter will not run the code in a browser, or in NodeJS. It will try to run it using whatever application you have associated with .js files. The Windows default, which is what your computer is using, is to use Windows Script Host (as you can see in your error message). WSH provides a runtime environment that's quite different from NodeJS and quite different from a browser.
If you read the dialogue carefully you'll see its title is "Windows Script Host", not Node. In fact Node is a command-line tool that doesn't launch dialogues or other widgets. Your screenshot clearly shows you were doing it just fine and then eventually forgot to type node in your command:
FYI, Windows Script Host is a tool that's similar to Node (a server-side ECMAScript engine) but belongs to another vendor (Microsoft), uses a different ECMAScript implementation (JScript) and possibly hasn't been updated in 10 years. That means that features and available libraries are completely unrelated to those in Node.
I've made a real time chat application with node and socket io and it is running well in my local machine. But its time to run it on my live windows server. I can't understand to how set it up there. Do I need to upload the files to the server or I've to install node js and npm modules in the server and then upload the files. And how I can do these? How I'll run the command prompt as we do in local machine like node chat.js ? Any help is appreciated.
Thanks in advance.
You can use a deployment client like Capistrano or you can just upload your source files then run npm install (assuming your have node installed) followed by your commands to bring up the server. I'd suggest using a framework like meteor or sails to make deployment easier. Or using a cloud solution like heroku.
You can use Jenkins for deploying your app to server. Running bash commands and setting builds are much more easier.
Keep it simple:
Download and install NodeJS, NPM (here)
You need to establish a simple way to move your files to the remote server. Since you can run your code and do the development at your local machine, I recommend you to use github for this purpose. Set up a repository and clone it at your remote server. Then, you can always push and pull your changes using git.
You need to establish a simple way to run your code at the remote server. Since you use Windows, I recommend you to create a .bat file that does all the preparations and runs your code. In the simplest case, it would contain node path\to\project\chat.js. Then, run this file using a console. If you're going to use github, you probably should include this .bat file to your repository.
Good luck!