var http = require('http');

var server = http.createServer();

server.listen()

console.log(server.address()); //打印端口信息

error事件

server.on('error', function (err)){

  console.log(err);

});

server.on('listening', function(){

  console.log('listening');

} );

server.on('request', function(){

  console.log('有客户请求来了');

}); //回调函数

server.on('request', function(req, res){

  console.log('有客户请求来了');

  console.log(req);

  //res是返回的东西

  res.setHeader('名称', '值');

  res.writeHead(200, '返回值显示的附带内容', {

    'content-type' : 'text/html; charset=utf-8',  //将返回的值输出文本为html,数据类型

    'content-type' : 'text/plain', //将返回的值输出为纯文本的

  });

  res.write('<h1>这个是返回信息<h1>');

}); //回调函数

server.listen(8080, 'localhost');

24,25-request对象的更多相关文章

  1. request对象常用API 获取请求参数的值 request应用 MVC设计模式

    1 request对象常用API   1)表示web浏览器向web服务端的请求   2)url表示访问web应用的完整路径:http://localhost:8080/day06/Demo1     ...

  2. webService通过response和request对象传输文件

    <code class=" hljs java">package gacl.response.study; 2 3 import java.io.IOException ...

  3. scrapy之Request对象

    我们在使用scrapy框架的时候,会经常疑惑,数据流是怎么样在各个组件中间传递的.最近经常用scrapy+selenium爬取淘宝,又因为今天周五心情好,本宝宝决定梳理一下这方面知识. scrapy中 ...

  4. request 对象和 response 对象

    Web服务器收到客户端的http请求,会针对每一次请求,分别创建一个用于代表请求的request对象.和代表响应的response对象 HttpServletResponse HttpServletR ...

  5. 通过Request对象对cookie的设置、获取

    <html> <head></head> <body> <% request.setCharacterEncoding("UTF-8&q ...

  6. Volley(二)—— 基本Request对象 & RequestQueue&请求取消

    详细解读Volley(一)—— 基本Request对象 & RequestQueue&请求取消 Volley它非常适合去进行数据量不大,但通信频繁的网络操作,而对于大数据量的网络操作, ...

  7. JSP内置对象--request对象

    本文主要介绍JSP中的request对象 request对象的主要方法: setAttribute(String name,Object):设置名字为name的request的参数值 getAttri ...

  8. django基础2: 路由配置系统,URLconf的正则字符串参数,命名空间模式,View(视图),Request对象,Response对象,JsonResponse对象,Template模板系统

    Django基础二 request request这个参数1. 封装了所有跟请求相关的数据,是一个对象 2. 目前我们学过1. request.method GET,POST ...2. reques ...

  9. 10 Servlet+Http+Request对象

    1.Servlet的体系结构 Servlet -- 接口----->GenericServlet -- 抽象类------->HttpServlet -- 抽象类 (1)GenericSe ...

  10. Web-从Java Request对象到HTTP协议

    https://mp.weixin.qq.com/s/PjcA22STEDGwRxVQweObQQ Java Web中的Request对象是哪里来的?Response对象的角色是什么? Java We ...

随机推荐

  1. Seek the Name, Seek the Fame---poj2752(kmp中的Next数组)

    题目链接:http://poj.org/problem?id=2752 题意就是求出是已知s串的前缀的长度x,并且要求此前缀也是s串的后缀:求出所有的 x : Next[i]的含义是前i个元素的前缀和 ...

  2. 使用python的logging模块(转)

    一.从一个使用场景开始 开发一个日志系统, 既要把日志输出到控制台, 还要写入日志文件 import logging # 创建一个logger logger = logging.getLogger(' ...

  3. Django中对静态文件的支持(转)

    英文原文:[http://agiliq.com/blog/2013/03/serving-static-files-in-django/] 译文:[http://segmentfault.com/a/ ...

  4. mysql 迁移数据

    一.导出导入所有数据库的数据 1.导出 mysqldump -u root -p123456 --all-databases > all.sql 2.导入 mysql -u root -p123 ...

  5. js-jquery-003-条形码-二维码【QR码】

    一.基本使用 插件地址:https://github.com/jeromeetienne/jquery-qrcode 1.首先在页面中加入jquery库文件和qrcode插件. <script ...

  6. 我的第一次NGS分析操作

    部分参考自:生物信息学100个基础问题 —— 番外2: 用Anaconda快速搭建生物信息学分析平台 - 孟浩巍的文章 - 知乎 https://zhuanlan.zhihu.com/p/357114 ...

  7. mariadb多源复制 muiltil source replication

    环境:centos-6.5      Mariadb:10.1.13-MariaDB 多源复制:企业数据库中写的需求较大,以至于I/O负载比较大,那么就必须把写的操作分摊到多台主服务器上进行,然后在将 ...

  8. TWebBrowser静音

    procedure TForm1.FormCreate(Sender: TObject); var   hDSound: Cardinal;   pDirectSoundCreate: Pointer ...

  9. Django:学习笔记(9)——用户身份认证

    Django:学习笔记(9)——用户身份认证 User

  10. JavaScript:传对象数组到后台

    页面: <script> function improve() { var improveForm = $('#improveForm'); if (!improveForm.valid( ...