首页 > 技术文章 > Node.js入门:Hello World

liusuqi 2014-05-19 09:21 原文

  马上开始我们第一个Node.js应用:“Hello World”。打开你的编辑器,创建一个hello.js文件。编写代码保存该文件,并通过Node.js来执行。
  • 控制台输出
1 console.log('hello, nodejs.') ; 

  • Web输出
1 var http = require("http"); 
2 http.createServer(function(request, response) { 
3     response.writeHead(200, {"Content-Type": "text/html"}); 
4     response.write("Hello World!"); 
5     response.end(); 
6 }).listen(8000); 
  打开浏览器地址栏输入http://localhost:8000/,可以在网页上看到输出结果。

推荐阅读