//引入依赖 var express = require('express'); var utility = require('utility'); //建立实例 var app = express(); app.get('/', function(req, res){ //取值 var q = req.query.q; //使用utility模块计算md5 var md5Value = utility.md5(q); res.send(md5Value); }); app.listen(3000, function(req, res){ console.log('app is running at port 3000'); });
运行$ node app.js,访问http://localhost:3000/,报错
1 2 3 4 5 6 7 8 9 10 11
TypeError: Not a string or buffer at TypeError (native) at Hash.update (crypto.js:119:16) at Object.hash (/Users/admin/Desktop/lesson2/node_modules/utility/lib/crypto.js:31:7) at Object.md5 (/Users/admin/Desktop/lesson2/node_modules/utility/lib/crypto.js:44:18) at /Users/admin/Desktop/lesson2/app.js:9:25 at Layer.handle [as handle_request] (/Users/admin/Desktop/lesson2/node_modules/express/lib/router/layer.js:95:5) at next (/Users/admin/Desktop/lesson2/node_modules/express/lib/router/route.js:131:13) at Route.dispatch (/Users/admin/Desktop/lesson2/node_modules/express/lib/router/route.js:112:3) at Layer.handle [as handle_request] (/Users/admin/Desktop/lesson2/node_modules/express/lib/router/layer.js:95:5) at /Users/admin/Desktop/lesson2/node_modules/express/lib/router/index.js:277:22