0

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.

1
  • 1
    Node 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. Commented Jan 14, 2014 at 10:35

1 Answer 1

2

You need to:

  1. Write JavaScript that will act as an HTTP server (there is an example of this on the node.js homepage.
  2. Run that through Node on the command line.
  3. 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
Sign up to request clarification or add additional context in comments.

8 Comments

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.
Yes, that's right, unless you use something like nodemon
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
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.
So does node.js have javascript syntax or completely different syntax.
|

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.