node.js 的基本信息 node.js 是一个机遇 Chrome JavaScrip t运行时建立的一个平台。 node.js 是一个事件驱动 I / O 服务端的javaScript环境。 node.js 的开发语言是 javaScript,所以是事件驱动的。 node.js 没有浏览器,没有 dom,没有 onclick 之类的东西。
node.js 下载安装 node.js 下载安装配置环境
查看当前 node.js 的版本
node -v使用 node 命令来执行 js 文件
node demo1使用 node.js 来创建一个 http 服务,要由以下三个部分组成
引入 http 模块,require;创建服务器;处理相应与请求;request 、response 介绍
request 和 response是服务器创建的两个对象,request 封装了浏览器发送过来的所有数据,获取浏览器发送过来的信息使用 request 对象,使用浏览器展示信息使用 response 对象。
// 引入一个模块,把模块保存在_http变量当中 var _http = require('http'); //console.log('_http'); _http.createServer(function(request,response){ //http 头部的信息 //状态码: 200 //内容的类型: text/plain, text/html, xml response.writeHead(200,{'Content-Type':'text/plain ;charset=utf-8'}); //向客户端发送数据 response.end('第一个服务'); }).listen(2244); //控制台打印信息 console.log('2244已经创建')每次运行都要重新启动node.js,charset=utf-8 防止乱码的出现 text/plain 纯文本,text/html 以html的方式输出
