I have installed node.js and have a file example.js. It contains a simple hello world javascript script. So I can use node.js to run it on cmd by the command 'node example.js' but how can I use node.js to run it on the broswer.Also does anyone know if node.js is supported by web hosts like GoDaddy and Network Solutions. Thanks in Advance.
-
1Node is not supported on any shared hosting that I know of, you will most probably have to go for a VPS. As far as running it in browser is concerned, you can code a HTTP server in Node and then pass the javascript code in an HTML document as response to incoming requests.Chetan Bhasin– Chetan Bhasin2014-01-14 10:35:12 +00:00Commented Jan 14, 2014 at 10:35
Add a comment
|
1 Answer
You need to:
- Write JavaScript that will act as an HTTP server (there is an example of this on the node.js homepage.
- Run that through Node on the command line.
- Point the browser at the URL for the server you just started.
In general, shared hosting will not provide Node support. You should look for either:
- hosting that specifically advertises support for Node
- a VPS
- a dedicated server
8 Comments
Abhishek Mhatre
All right I have setup the javscript file that runs as HTTP server from the node.js homepage but after running it once, if I make a change in the .js file, I have to run it again using cmd for the browser to show the change.
Abhishek Mhatre
Yeah i can probably live with that. But the http server file that you told me to create only runs node.js on the browser and the javascript is only shown on the cmd. So can't I execute javascript on the browser using node.js
Quentin
If you want to display the results in the browser, then you have to output them to the HTTP response instead of to the console.
Abhishek Mhatre
So does node.js have javascript syntax or completely different syntax.
|