First, go to http://nodejs.org to download the installation. The version I'm under is 0.10.28. The installation is simple and the next step is.
My installation directory is C:\Program Files\nodejs. At this point, use the NODE-V command to view the installed version
First, HelloWorld
Create a new file in the node. JS installation directory hello.js a line of code
| 1 |
console.log(‘hello, nodejs.‘) ; |
Go to the command line console and go to the node. js directory to knock node Hello.js
The console outputs "Hello, Nodejs."
Second, the web version of the HelloWorld
Create a new http.js in the node. JS installation directory with the following code
| 1 2 3 4 5 6 |
varhttp = require("http"); http.createServer(function(request, response) { response.writeHead(200, {"Content-Type": "text/html"}); response.write("Hello World!"); response.end(); }).listen(8000); |
Start the service on the command line and tap node Http.js
Then open the browser address bar input http://localhost:8000/, see the page output Hello world! It was a success.