node.js介绍及Win7环境安装测试

来源:互联网 发布:java设置编码格式 编辑:程序博客网 时间:2024/05/16 23:54

下载安装:

点击http://nodejs.org/,进入官网,下载windows版本:http://nodejs.org/dist/v0.6.6/node-v0.6.6.msi

下载完成后,直接点击安装:

默认安装目录:C:\Program Files\nodejs

安装完成,不生成快捷方式,手动去安装目录查看即可;

安装完成后目录下,一个node.exe\npm.cmd\node_modules(文件夹);

安装包会自动把安装路径写入环境变量path中,可进行全局访问;

 

安装测试:

打开cmd命令窗口,输入node,回车;

cmd窗口会出现”>”输入".help”,回车;

> .help 
.break  Sometimes you get stuck, this gets you out 
.clear  Break, and also clear the local context 
.exit   Exit the repl 
.help   Show repl options 
.load   Load JS from a file into the REPL session 
.save   Save all evaluated commands in this REPL session to a file

恭喜您基本安装成功!

开始一个HelloWorld:

在D盘建立一个文件夹:Nodejs

在些文件夹下新建一个文本文件,并输入

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 at http://127.0.0.1:8124/');

保存,并重命名文件为"HelloWorld.js”;

打开cmd命令窗口:

D:\Nodejs>node HelloWorld.js 回车;

Server running at http://127.0.0.1:8124/

在本地浏览器地址中,输入:http://127.0.0.1:8124/,OK,欢迎进入Node.js世界;

提示:在命令窗口下,按Ctrl+Break可结束刚启动HelloWorld--Web服务;

 

0 0
原创粉丝点击