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赋值
输出一个键值对象{}