Script path in nodesjs

I want to run phonegap and wet my hands with mobile development. Everywhere I see nodejs as a prerequisite, I have downloaded it and it really seems different from wamp that I am used to.
The tutorial just says to load an external script I should write the script $ node myJsScript.js on the CLI, well there is no path to the script location, besides I am not too good at CLI, how do I cross this step, and if you have any “node fro the novice” like resource I will be grateful thanks in advance


Have you got Node installed? Which OS are you using?
Resource-wise, try this:

Yes it is installed. I work on windows, 8 to be specific.
console.log(), works but not $ node myJsScript.js. So where is the js script to be stored? (wamp provides a www/ directory)
I have that book, but it is talking about non relational db but I will wish to go ahead with related db for a start, reason why I had to put it on halt.
Right now I just want to know the basics, not db access management, just loading a js script and seeing the output and seeing the result on my browser too.
Thanks in advance

Open a command prompt anywhere on your PC (Windows + R > cmd), then type:

node -v

What’s the output?


So, make a file called script.js (or whatever) and place the following content in the file:

var http = require('http');

var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end("Hello World!");

console.log("Server running at");

In the shell type:

node script.js

You should see:

Server running at

Then, open a browser and navigate to: http://localhost:8000/

You should see the message “Hello World!”

You can read more here:

1 Like

on cmd it threw this:
and on my browser nothing

or should I run it on the node CLI?

You must run the command from the same directory as the file, or specify the path to the file accordingly.

I really do not understand that?

Running dir on cmd gives

ok let me try it!

wow it worked! thanks so much, I will continue from here.
but please what about the Node.js CLI, would it act the same??

I don’t really understand the question.
Could you rephrase?

sorry if I am using the terms wrongly. Will the nodejs CLI do the same job as the windos cmd CLI?

Do you mean the thing you get into if you type node from the Windows command prompt?

I just want to know if both windows will produce the same thing, because working on the Node.js CLI seems different or is it just a js console?

The Node.js CLI is what’s known as a REPL (short for ‘Read-Eval-Print Loop’). It can be extremely useful for experimenting with Node.js and debugging code, but is essentially “just” a JS console". You can read a bit more about it here:

You could manually enter the “Hello World” program into Node’s CLI and see the same output, but the question is why would you want to?

Thanks again, all of this information will be helpful!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.