node.jsの安装helloWorld
2017-01-16 13:31
369 查看
下载
下载地址:https://nodejs.org/en/安装
测试
dos下:npm查看npm版本 npm -v
查看node.js版本 node -v
简单的helloWorld
新建hello.js文件,console.log("hello,world");
右击--打开dos窗口
node hello.js
以上是最简单的helloworld
交互的helloWorld
因为node.js主要是和服务端的交互,下面代码是完成的一次和服务端交互的node.jsvar http=require('http');
http.createServer(function(request,response){
response.writeHead(200,{'Content-Type': 'text/html; charset=utf-8'});
if(request.url!="/favicon.ico"){//清楚第二次次访问
console.log('访问');
response.write('hello,world');//http请求内容
response.end('结束了');//请求结束,否则浏览器会一直转
}
}).listen(8000);
console.log('服务运行在本地8000端口');
代码步骤总结:
1.获取http对象
2.创建服务
2.1请求,和反应
2.2写协议头
...写内容...
2.3写协议尾
3.监听8000端口
下一次总结学习node.js的函数
相关文章推荐
- 安装Node.js,helloworld
- 《Node.js简记》 安装Node.js并实现Helloworld
- 【Node.js】初体验之安装和HelloWorld
- [浅学] 1、Node.js尝试_安装&运行第一个helloworld
- Node.js的安装 - "HelloWorld”篇
- 详解如何在ubuntu上安装node.js
- Node.js 安装及npm的安装
- nginx and node.js配合使用 helloworld
- 虚拟机下的CentOS环境中安装Node.js
- 在windows 7下安装node.js
- 安装node.js
- 在Windows上安装Node.js模块的方法
- node.js安装
- 在Windows平台上安装Node.js及NPM模块管理
- 在windows 下安装node.js
- Node.js 安装及npm的安装
- 如何安装Node.js
- centOS下通过NPM安装和配置node.js+socket.io+connect在线聊天的详细教程
- linux 安装node.js
- 如何安装Node.js