Node(2) First Code
来源:互联网 发布:淘宝太坑了女主角视频 编辑:程序博客网 时间:2024/05/26 02:52
you can use a command line prompt to do node
meta-commands
.help shows help menu
.clear wipes out variables
Hello World
//include http library into the program//http object has the http library functionalityvar http = require( 'http' );//unlike php, you have to create the server//listen to port 8124http.createServer( function(req, res){//set http response headerres.writeHead(200, { 'Content-Type': 'text/plain'});res.write( 'Hello' );res.end( ' World\n');}).listen(8124, "127.0.0.1" );//print a message to stdoutconsole.log( 'Server running at http://127.0,0.1:8124/');
http.createServer([requestListener])
Returns a new web server object.
requestListener is optional and added to request event
response functions
response.writeHead(statusCode, [reasonPhrase], [headers])
Sends a response header to the request. The status code is a 3-digit HTTP status code, like 404. The last argument, headers, are the response headers. Optionally one can give a human-readable reasonPhrase as the second argument.
response.write(chunk, [encoding])
write a chunk of string or buffer to response
response.end([data], [encoding])
This method signals to the server that all of the response headers and body has been sent
Listening to event
server.on('event', function(a, b, c) { //do things});server is an instance of eventEmitter, eventEmitter has two methodson and emit. emit emits an event,on listens to the event
A variation of the example would be:
var http = require( "http" );var server = http.createServer();server.listen( 9000 );server.on( 'request', function(req, res ){res.writeHead( 200, { "Content-Type": "text/plain" });res.write( "Hello World" );res.end();});console.log( "localhost:9000 running" );
- Node(2) First Code
- First code book 2章
- Code First
- code first
- code first
- First Code
- Code First :使用Entity. Framework编程(2)
- 第一章 欢迎来的Code First(2)
- Code First DataAnnotations
- Code First一些问题
- Code first, DB update
- 【Code First】 Data Seed
- ef-->code first-->Migrations
- ef code first例子
- code first 迁徙数据
- Code First Tutorisal
- Code First 之类继承
- EF Code first
- TCP状态图
- 惊爆眼球!视频解读游戏中DX9与DX11画质差别
- hr数据库
- i++与++i经典分析
- Direct3D 11 API 改编自Intro_to_Direct3D10
- Node(2) First Code
- Direc3D设备对象
- Direct3D 11设备介绍
- DX11多线程学习与思考
- "http://android.git.kernel.org/repo 打不开"问题解决
- HR代码
- 微博 0auth2.0 验证
- 2012 -7-25 周三 计划
- Android控制台命令am简介