---
title: "nodejs入门"
author: "zhouyrt"
date: "2012-01-05T16:54:45Z"
tags: []
categories: ["编程语言"]
slug: "nodejs"
draft: false
lastmod: "2012-01-05T21:19:09Z"
id: 1336131
url: "https://snandy.iteye.com/blog/1336131"
---

首先，去[http://nodejs.org](http://nodejs.org/) 下载安装。我下的版本是0.6.6。安装很简单，下一步下一步就哦了。

我的安装目录是C:\\Program Files (x86)\\nodejs。

 

 

 

**一、helloworld**

在nodejs安装目录中新建一个文件hello.js，里面敲一行代码

 

```
console.log('hello, nodejs.') ;
```

进入命令行控制台，进入到nodejs目录敲node hello.js

![](http://dl.iteye.com/upload/attachment/616779/e723342a-47c5-3250-b025-d48a6c6e3763.png)

![](http://dl.iteye.com/upload/attachment/616805/ab62501b-e3a7-3e16-85aa-f3a7cfda416e.png)

 

控制台输出了“hello, nodejs.”

 

 

**二、web版的helloworld**

在nodejs安装目录中新建一个http.js，代码如下

```
var http = require("http");
http.createServer(function(request, response) {
    response.writeHead(200, {"Content-Type": "text/html"});
    response.write("Hello World!");
    response.end();
}).listen(8000);
```

 

在命令行中启动服务，敲 node  http.js

![](http://dl.iteye.com/upload/attachment/616807/ce897e63-d3c0-39c5-b940-e36b9c7a5f7c.png)

 

然后打开浏览器地址栏输入http://localhost:8000/，看见页面上输出Hello World! 就成功了。