简体   繁体   中英

node.js questions for beginners

I am a beginner in nodeJS, and I have some questions which I'd like answered.

  1. 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?

  2. 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?

  1. 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.

  2. 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' ]
  1. First "command prompt" is a node.js interpreter. You can also run it by executing node in window console. When you entering "node code.js" you start "First command prompt" to execute code.js file. If you launch it without any script you can enter you script directly in interpreter
  2. Yes, node.js could be used to access to db like php or python. With main difference that you don't need to install webserver(apache, nginx) for interpreter, like in PHP or Python, because node.js can create webserver for you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM