error info
ReferenceError: crypto is not defined at exports.doReg (/home/xxx/Project/nodeJs/microblog/routes/index.js:85:12) at callbacks (/home/xxx/Project/nodeJs/microblog/node_modules/express/lib/router/index.js:165:11) at param (/home/xxx/Project/nodeJs/microblog/node_modules/express/lib/router/index.js:139:11) at pass (/home/xxx/Project/nodeJs/microblog/node_modules/express/lib/router/index.js:146:5) at Router._dispatch (/home/xxx/Project/nodeJs/microblog/node_modules/express/lib/router/index.js:173:5) at Object.router (/home/xxx/Project/nodeJs/microblog/node_modules/express/lib/router/index.js:33:10) at next (/home/xxx/Project/nodeJs/microblog/node_modules/express/node_modules/connect/lib/proto.js:190:15) at Object.handle (/home/xxx/Project/nodeJs/microblog/app.js:47:5) at next (/home/xxx/Project/nodeJs/microblog/node_modules/express/node_modules/connect/lib/proto.js:190:15) at store.get.next (/home/xxx/Project/nodeJs/microblog/node_modules/express/node_modules/connect/lib/middleware/session.js:302:9) POST /reg 500 59ms
关于这个问题,是不是要单独安装相关的module?
crypto是内置模块,直接var crypto = require('crypto')
即可使用。楼主是新手么?!!!!
的确是新手。 还有一个问题
TypeError: Object #<IncomingMessage> has no method 'flash’ at exports.doReg (/home/xxx/Project/nodeJs/microblog/routes/index.js:81:8)
at callbacks (/home/xxx/Project/nodeJs/microblog/node_modules/express/lib/router/index.js:165:11)
at param (/home/xxx/Project/nodeJs/microblog/node_modules/express/lib/router/index.js:139:11)
at pass (/home/xxx/Project/nodeJs/microblog/node_modules/express/lib/router/index.js:146:5)
at Router._dispatch (/home/xxx/Project/nodeJs/microblog/node_modules/express/lib/router/index.js:173:5)
at Object.router (/home/xxx/Project/nodeJs/microblog/node_modules/express/lib/router/index.js:33:10)
at next (/home/xxx/Project/nodeJs/microblog/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Object.handle (/home/xxx/Project/nodeJs/microblog/app.js:47:5)
at next (/home/xxx/Project/nodeJs/microblog/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at store.get.next (/home/xxx/Project/nodeJs/microblog/node_modules/express/node_modules/connect/lib/middleware/session.js:302:9)
POST /reg 500 11ms ^C[root@localhost microblog]# vim /home/xxx/Project/nodeJs/microblog/routes/index.js [root@localhost microblog]# node app.js Express server listening on port 3000 GET / 304 25ms GET /reg 304 9ms TypeError: Object #<ServerResponse> has no method 'redircet’ at exports.doReg (/home/xxx/Project/nodeJs/microblog/routes/index.js:82:15)
at callbacks (/home/xxx/Project/nodeJs/microblog/node_modules/express/lib/router/index.js:165:11)
at param (/home/xxx/Project/nodeJs/microblog/node_modules/express/lib/router/index.js:139:11)
at pass (/home/xxx/Project/nodeJs/microblog/node_modules/express/lib/router/index.js:146:5)
at Router._dispatch (/home/xxx/Project/nodeJs/microblog/node_modules/express/lib/router/index.js:173:5)
at Object.router (/home/xxx/Project/nodeJs/microblog/node_modules/express/lib/router/index.js:33:10)
at next (/home/xxx/Project/nodeJs/microblog/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Object.handle (/home/xxx/Project/nodeJs/microblog/app.js:47:5)
at next (/home/xxx/Project/nodeJs/microblog/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at store.get.next (/home/xxx/Project/nodeJs/microblog/node_modules/express/node_modules/connect/lib/middleware/session.js:302:9)
code: exports.doReg = function(req, res){ if (req.body[‘password-repeat’] != req.body[‘password’]) { //req.flash(‘error’ ,‘twice password not correct!’); // this error return res.redircet(’/req’); // this error } // if password correct , we create the hash value var md5 = crypto.createHash(‘md5’); var password = md5.update(req.body.password).digest(‘base64’); var newUser = new User({ name: req.body.username, password: password, });
req.flash()为什么就不能用了?
不知道,看不懂!没看过你这个microblog的代码。
建议你先检查一下Express的版本是否一致 express 3.x 中删除了req.flash(),参考这里:https://github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.x
或者直接安装express 2.x版本
/home/xxx/Project/nodeJs/microblog/node_modules/mongodb/lib/mongodb/db.js:1808 if(callback) callback(new Error(“no open connections”), null); ^ TypeError: object is not a function
使用了 res.redirect(’/’); 出现上面的报错
@papaivan 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
问题太复杂了,不懂,楼下的大神给解说一下吧。。。
我查看了一下node_modules/mongodb/lib/mongodb/db.js文件
Db.prototype._executeInsertCommand = function(db_command, options, callback) { 1780 var self = this; 1781 1782 // Unpack the parameters 1783 if (typeof callback === ‘undefined’) { 1784 callback = options; 1785 options = {}; 1786 } 1787 1788 // Check if the user force closed the command 1789 if(this._applicationClosed) { 1790 if(typeof callback == ‘function’) { 1791 return callback(new Error(“db closed by application”), null); 1792 } else { 1793 throw new Error(“db closed by application”); 1794 } 1795 } 1796 1797 // If the pool is not connected, attemp to reconnect to send the message 1798 if(self._state == ‘connecting’ && this.serverConfig.autoReconnect) { 1799 process.nextTick(function() { 1800 self.commands.push({type:‘insert’, ‘db_command’:db_command, ‘options’:options, ‘callback’:callback}); 1801 }) 1802 } else if(!this.serverConfig.isConnected() && this.serverConfig.autoReconnect) { 1803 this._state = ‘connecting’; 1804 // Retry command 1805 __retryCommandOnFailure(this, this.retryMiliSeconds, this.numberOfRetries, __executeInsertCommand, db_command, options, callback); 1806 } else if(!this.serverConfig.isConnected() && !this.serverConfig.autoReconnect && callback) { 1807 // Fire an error to the callback if we are not connected and don’t do reconnect
1808 if(callback) callback(new Error(“no open connections”), null); 1809 } else { 1810 // If we have a 1811 if(this.serverConfig instanceof ReplSet && this.serverConfig._checkReplicaSet()) { 1812 // Execute insert command 1813 __executeInsertCommand(self, db_command, options, callback) 1814 1815 var replSetGetStatusCommand = DbCommand.createAdminDbCommandSlaveOk(self, {replSetGetStatus:1}, {}); 1816 // Do a freaking ping 1817 __executeQueryCommand(self, replSetGetStatusCommand, {readPreference:ReadPreference.SECONDARY_PREFERRED}, function(_replerr, _replresult) { 1818 // Force close if we are disconnected 1819 if(self._state == ‘disconnected’) { 1820 self.close(true); 1821 return; 1822 }
加粗的就是抛出异常的地方 为什么我使用 res.redirect(’/’); 转向main page 的时候会报这个错,
同时页面会出现: can not connect the 127.0.0.1:3000
而 mongod 会出现 end connection…
我只想在这里告诉大家 问题解决了。 但是这个问题的 Root cause还需要尝试。
你这个microblog的源码在哪里? 代码都没看到,你是要让大家猜那是什么出错么? 俺还没到那个可以猜出来的水平。。。
界面会超界限????????????。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
界面会超界限????????????。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
界面会超界限????????????。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
界面会超界限????????????。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
是加到app.js里么