zoukankan      html  css  js  c++  java
  • Node.js基础

    http
    数据请求
    前台->form, ajax, jsonp
    后台

    get数据在url中
    post不在url中

    image.png

    image.png

    image.png

    image.png

    const http = require('http');
    const urlLib = require('url');
    http.createServer(function(req,res){
    var obj = urlLib.parse(req.url, true);
    var url = obj.pathname;
    var GET = obj.query;
    console.log(url, GET);
    // req获取前台请求数据
    res.write('aaa');
    res.end();
    }).listen(8081);
    

    image.png

    const http=require('http');
    const urlLib = require('url');
    http.createServer(function(req,res){
    var obj = urlLib.parse(req.url, true);
    var url = obj.pathname;
    var GET = obj.query;
    console.log(url,GET);
    // req获取前台请求数据
    res.write('aaa');
    res.end();
    }).listen(8081);
    

    image.png

    var http=require('http');
    http.createServer(function(req,res){
    }).listen(8080);
    

    image.png

    image.png

    (function(){
    var a='hello';
    var b='dashu';
    console.log(a+' '+b);
    })();
    
    var module = {
     a="da",
     b: {}
    };
    var load = function(module){
    function greet(name) {
     console.log('hello');
    }
    module.exports = greet;
    return module.exports;
    }
    var exported = load(module);
    save(module, exported);
    
    var greet = require('./hello');
    

    module.exports vs exports

    function da() {
    }
    function shu(name){
    }
    module.exports = {
    da:da,
    shu:shu
    };
    
    exports.hello = hello;
    exports.greet =greet;
    

    image.png

    image.png

    var load=function(exports,module) {
     ...
    return module.exports;
    };
    var exported=load(module.exports, module);
    

    image.png

    image.png

    输出的是一个函数或数组
    只能给module.exports赋值

    输出一个键值对象{}


    请点赞!因为你的鼓励是我写作的最大动力!

    官方微信公众号

    吹逼交流群:711613774

    吹逼交流群

  • 相关阅读:
    基于摸板匹配的目標跟蹤算法
    spoj 2713 Can you answer these queries IV
    zoj 3633 Alice's present
    hdu 3642 Get The Treasury
    poj 1195 Mobile phones
    poj 2760 End of Windless Days
    zoj 3540 Adding New Machine
    spoj 1716 Can you answer these queries III
    spoj 1043 Can you answer these queries I
    spoj 2916 Can you answer these queries V
  • 原文地址:https://www.cnblogs.com/dashucoding/p/11140216.html
Copyright © 2011-2022 走看看