Tag: 表示

Sails.js swig模板不工作

我安装了Sails.js 0.9.4,并创build了一个使用swig模板引擎和下面的命令的应用程序: sails new sailsproject–template=swig 当我尝试通过sails lift运行应用程序时,出现以下错误: C:\Users\akis\Desktop\sailsproject>sails lift C:\Users\akis\AppData\Roaming\npm\node_modules\sails\node_modules\express\lib\ap plication.js:174 if ('function' != typeof fn) throw new Error('callback function required'); ^ Error: callback function required at Function.app.engine (C:\Users\akis\AppData\Roaming\npm\node_modules\sails \node_modules\express\lib\application.js:174:38) at Array.loadExpress [as 1] (C:\Users\akis\AppData\Roaming\npm\node_modules\ sails\lib\express\index.js:70:7) at listener (C:\Users\akis\AppData\Roaming\npm\node_modules\sails\node_modul es\async\lib\async.js:462:46) at C:\Users\akis\AppData\Roaming\npm\node_modules\sails\node_modules\async\l ib\async.js:416:17 at Array.forEach (native) at _each (C:\Users\akis\AppData\Roaming\npm\node_modules\sails\node_modules\ async\lib\async.js:32:24) at Object.taskComplete (C:\Users\akis\AppData\Roaming\npm\node_modules\sails \node_modules\async\lib\async.js:415:13) at […]

运行快速代码时发生ECONNREFUSED错误

我无法运行服务器……我收到错误ECONNREFUSED 如何解决这个错误! 当我试图使用不同的端口….所有给我同样的错误! ubuntu@ip-MyIP:~/rainmelon/projects/FindMyBuffet$ node app.js Express server listening on port 7005 Error: connect ECONNREFUSED at errnoException (net.js:884:11) at Object.afterConnect [as oncomplete] (net.js:875:19) ——————– at Handshake.Sequence (/home/ubuntu/rainmelon/projects/FindMyBuffet/node_modules/mysql/lib/protocol/sequences/Sequence.js:15:20) at new Handshake (/home/ubuntu/rainmelon/projects/FindMyBuffet/node_modules/mysql/lib/protocol/sequences/Handshake.js:9:12) at Protocol.handshake (/home/ubuntu/rainmelon/projects/FindMyBuffet/node_modules/mysql/lib/protocol/Protocol.js:42:50) at Connection.connect (/home/ubuntu/rainmelon/projects/FindMyBuffet/node_modules/mysql/lib/Connection.js:73:18) at Object.<anonymous> (/home/ubuntu/rainmelon/projects/FindMyBuffet/app.js:15:12) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10)

JSONP在node.js中未定义,使用.send会导致意外的令牌错误

我在我的node.js函数中使用JSONP: this.send(JSON.stringify({ type: 'hello', username: this.data('username'), friends: friends })); 但是,它给了我一个意想不到的令牌“:”错误(我没有看到在JSON中)。 在阅读这篇文章之后: jsonp中的'Uncaught SyntaxError:Unexpected token:' 我发现它可能是一个JSON / JSONP的问题。 所以我改变了我的代码: this.jsonp(JSON.stringify({ type: 'hello', username: this.data('username'), friends: friends })); 但是,它说这没有方法“jsonp”。 我不能使用发送,因为我在客户端使用jsonp。 这很奇怪,因为我可以在任何地方使用jsonp,但是在这里。 这里是user.js文件中的一些函数。 User.prototype.send = function(code, message, callback) { this._send('listener', code, message, callback); }; User.prototype._send = function(type, code, message, callback) { if(!message && typeof code != 'number') { […]

express.js不在nodeunittesting中保存会话数据

更新底部! 我的node.js服务器使用express.js来pipe理会话。 login后,我将一些用户信息存储在req.session中。 我有一个注销端点,它只是在发送响应之前从req.session删除用户数据。 随着用户的每个请求,我使用authentication中间件来确保会话中仍然存在用户数据,因此删除会话对象中的用户数据将会导致后续authentication失败。 为了testing我的服务器,我有一个nodeunittestinglogin,调用几个端点,注销,然后尝试调用另一个端点。 我希望最后的端点在validation失败,因为我以前吹走了用户数据。 相反,当我最后一次打电话时,我的用户数据仍然存在 。 就好像删除它的注销电话没有被写回到会话存储中一样。 这是我的app.js: app.use(express.cookieParser('secretPassword')); app.use(express.cookieSession({key: 'someKey'})); … app.get('/logout', accounts.logout); app.get('/account', auth.authenticateSession, accounts.show); auth.js: exports.authenticateSession = function(req, res, next) { if (!req.session.user) { return res.json(401, { error: 'Access denied. You must be logged in to make this request.' }); } … } accounts.js:退出: exports.logout = function(req, res) { […]

expressjs可以做两个post路线吗?

我创build了一个Expressjs应用程序。 它包含公共,视图,路线文件夹和app.js文件。 我有一个post路由器“/”path像这样在app.js中, app.post('/', store.home_post_handler); 和玉码, #display #login form(method='post') | Enter your name if you want to be a ninja div input(type='text', name='username') input(type='submit', value='Log In') 我的问题是,是否有可能在一个页面中有两个post方法?

如何从expressjs获取表单中选定的单选button值?

我正在使用Expressjs,我的Jade代码创build一个应用程序, form(method='post', action='/listJobs') each item in myJobNames input(type='radio', name='jobNameRadio', val='#{item}') | #{item} br 我的文章处理程序 cur_Job = req.body.jobNameRadio; req.session.cur_Job = cur_Job; console.log(req.body); console.log(req.session.cur_Job); 但在console.log,我得到这个。 {jobNameRadio:'on'}上 如何获得所选单选button的值?

节点js函数需要一个返回值,但值来自callback,所以不能被返回

对于令人困惑的标题抱歉,我会试图解释 我正在使用expression式和自定义validation函数node.js像这样: app.post('/register', form( field("username").trim().required().custom(function(value) { //Works correctly if (!user.validUsername(value)) { throw new error("Invalid username"); } //Does not work due to callback user.uniqueUsername(value, function(uniqueUsername) { if (!uniqueUsername) { //Not unique, throw error throw new Error("username is already taken"); //Could be subsituted for return "whatever"; and it would still be the same problem } }); }), […]

NodeJS Express:#<Object>没有方法'parse'

当我使用以下命令创build一个新包时,NodeJS.express出现问题: express test_web 它创build成功,但是当我打开localhost:3000主页,它不能访问parse方法! 这是一个完整的页面它是什么来的: Express 500 TypeError: /Users/user/Documents/p/hello_test/views/index.jade:5 3| block content 4| h1= title > 5| p Welcome to #{title} Object #<Object> has no method 'parse' at detect (/Users/user/Documents/p/hello_test/node_modules/jade/node_modules/with/index.js:33:22) at addWith (/Users/user/Documents/p/hello_test/node_modules/jade/node_modules/with/index.js:8:28) at parse (/Users/user/Documents/p/hello_test/node_modules/jade/lib/jade.js:105:11) at Object.exports.compile (/Users/user/Documents/p/hello_test/node_modules/jade/lib/jade.js:142:9) at Object.exports.render (/Users/user/Documents/p/hello_test/node_modules/jade/lib/jade.js:196:15) at Object.exports.renderFile (/Users/user/Documents/p/hello_test/node_modules/jade/lib/jade.js:233:18) at View.exports.renderFile [as engine] (/Users/user/Documents/p/hello_test/node_modules/jade/lib/jade.js:218:21) at View.render (/Users/user/Documents/p/hello_test/node_modules/express/lib/view.js:76:8) at Function.app.render […]

用mongoosesorting阿尔法

我试图通过mongoose3.6.20sorting,我收到了一些意想不到的结果。 我有一个名字的公司名单。 起初我以为也许它是在区分大小写的方式。 基于文章,我期望是真实的。 我现在正在使用虚拟属性来排除sorting字段。 不过,我仍然得到意想不到的结果。 CompanySchema.virtual('name_lower').get(function(){ return this.name.toLowerCase(); }); 当我sorting Company.find().sort({ name_lower: 1 }); 我按照以下顺序得到它: 公司名 谷歌 公司名称(是testing重复) 我也输出我的虚拟财产的价值,它看起来是正确的。 没有可能导致第二个“公司名称”出现在Google之后的空白字符或时髦字符。 使用nodejs,express,mongoose。 我错过了什么或做错了什么? 更新: 根据答案中提供的信息,我重构了我的模式以包含一些规范化字段,并将其挂接到文档的预保存事件中,在那里我更新这些规范化字段并在将来的所有查询中使用它们进行sorting。 CompanySchema.pre('save', function(next){ this.normalized_name = this.name; }); 接下来,在我使用的模式中: var CompanySchema = mongoose.Schema({ … normalized_name: { type: String, set: normalize }, … }); 凡normalize是一个函数,现在,返回一个小写的值传递给它的值。 但是,这使得我可以很快地扩展它,并且可以快速地对其他可能需要sorting的领域进行相同的处理。

玉石模板引用一个项目与时期

我的数组是 {"Name.Value":"Joe", "Age.Value":65} 我的玉是 input(type='text', id='Name' value='#{Name.Value}') 我得到一个错误,因为它试图读取名称对象的属性值。 我怎样才能解决这个问题,而不改变我的数组键