实例代码test.js var http=require('http'); var url=require('url'); var querystring=require('querystring'); http.createServer(function(request, response) { var urlStr = request.url; var methodName = urlStr.substring(1, urlStr.indexOf('?')); console.log('me
node.js 获取cookie var Cookies ={}; if (req.headers.cookie != null) { req.headers.cookie.split(';').forEach(l => { var parts = l.split('='); Cookies[parts[0].trim()] = (parts[1] || '').trim(); }); }
var http=require('http') var url=require('url') var qs=require('querystring') http.createServer(onRequest).listen(3000) function onRequest(res,resp) { //第一种方式queryString模块的方式获取参数的方法 var arg=url.parse(res.url).query ; var nameValue=qs.parse(arg)['name
假如有个加密程序test.js,不想每次加密的时候都修改代码,直接通过控制台输入参数 var createHash = require('sha.js') var sha1 = createHash('sha1') var reqStr = process.argv.splice(2)[0] //获取控制台参数 var h = sha1.update(reqStr, 'utf8').digest('hex') console.log(reqStr) console.log(h.toUpperCa
//获取ip地址 getIPAdress() { let interfaces = require('os').networkInterfaces(); for (var devName in interfaces) { var iface = interfaces[devName]; ; i < iface.length; i++) { let alias = iface[i]; if (alias.family === 'IPv4' && alias.address !== '1