node.js questions for beginners
Problem
I am a beginner in Nodejs, and I have some questions which I'd like answered.
First, when I went to install nodeJS, it was installed with two different Command prompts. The first Command Prompt is blank, and shows ">". The second command prompt is a windows command prompt, but with the message "Your environment has been set up for using Node.js 0.8.18 (ia32) and NPM". By entering the code
node code.js
I am able to start running nodeJS with the second command prompt, but I don't know how to use the first command prompt that I described above. Could someone please explain to me what the first command prompt is used for?My second question as a beginner in nodeJS is about creating servers. I haven't gone to deep with what nodeJS can do. But if nodeJS can create a server, then would it be safe to assume that nodeJS can be used to create database software for something like PHP or Python to interact with?
Solution
The first command prompt is REPL, which means you just enter your command and it evaluates and keeps running. It is like a live console to test some functionality.
NodeJS can do many things, its event driven model is a good alternative to similar systems. NodeJS can communicate with database, another computer, or with user. It is just a platform with Javascript programming language. As it is stated on nodejs website, it is "
lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
"
EDIT: Example Interaction with REPL
$ nodejs
> process.version
'v0.8.18'
> var a = 5;
undefined
> var b = 5
undefined
> a + b
10
> var dns = require("dns");
undefined
> dns.resolve4("www.google.com",function(err,address){console.log(address); })
{ oncomplete: [Function: onanswer] }
> [ '173.194.35.144',
'173.194.35.145',
'173.194.35.146',
'173.194.35.147',
'173.194.35.148' ]
Discussion
View additional discussion.