Node.js 入门简介

来源:互联网 发布:d3.js的作用 编辑:程序博客网 时间:2024/05/16 18:21

入门简介

1.windows安装Node

从官网页面中(http://nodejs.org/)下载安装文件。


安装完成之后,运行Node.jscommand prompt

 

 

Node.js command prompt运行的结果如下图(看起来就像cmd)

2.运行Hello World!

先给出一个用Node写的“HelloWorld”的服务器端代码事例

var http = require('http'); 

http.createServer(function(request, response){

 response.writeHead(200,{'Content-Type':'text/plain'});

 response.end('Hello World\n');

}).listen(8124); 

console.log('Server running athttp://127.0.0.1:8124/');

运行

如何运行呢?将上述代码复制粘贴到example.js的文件中(注意后缀.js),然后在上面提到的Node.js command prompt命令行中运行这个文件。

node C:\Users\ocean\Desktop\test.js


 

服务器端的文件已经运行起来了,就这么简单!

在浏览器中输入:

http://localhost:8124/或者http://127.0.0.1:8124/ 得到如下页面



 

 

0 0
原创粉丝点击