Node.js入门:Hello World

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

Node.js入门:Hello World

  • 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);
Node.js入门:Hello World
  打开浏览器地址栏输入http://localhost:8000/,可以在网页上看到输出结果。