Tag: 表示

占位符段在快递中间件挂载点

使用Express时,我可以在路由string中使用占位符来定义路由,如下所示: app.get("/users/:user_id/photos", function(req,res){<blah>}); 然后在我的处理程序中,我可以使用req.params["user_id"]来获取URL中的任何内容,并在我的请求中使用它。 中间件可以挂载在某些path上,只有匹配该path的请求才会使用中间件。 我可以在中间件的装载path中使用占位符吗? 例如,我可以做些什么: app.use("/users/:user_id/photos", <middleware>); 然后在中间件里面有一些访问映射到的段的方法:user_id是? 编辑1: 我知道,我可以把中间件直接放在路由声明中,àla: app.get("/users/:user_id/photos", <middleware>, function(req,res){<blah>}); 随着应用程序的不断增长,看到这种情况会如何失控,并没有太多的想象。

快速AppFog上的错误,但不是在本地

我在AppFog上托pipe我的应用程序时出现错误。 50行,当我打电话给JSDOM …问题不出现在本地,我不明白为什么它不能在远程工作… 我的代码(在当地工作): exports.index = function(req, res) { Creation.findAll({where: "state = 1",order: 'id DESC', limit: 2}).success( function(creations) { Post.findAll({where: "state = 1",order: 'id DESC', limit: 2}).success(function(posts){ async.map(posts, function(postEntity, callback){ jsdom.env( // PROBLEM HERE postEntity.content, ["http://code.jquery.com/jquery.js"], function(errors, window) { if(errors) return callback(errors); postEntity.content = window.$("p").text(); callback(null, postEntity); } ); }, function(err, transformedPosts){ if(err) return callback(err); […]

Express js设置在哪里?

在快速文档中,有一个名为settings的部分: http : //expressjs.com/api.html#app-settings 但我无法弄清楚究竟应该去哪里(作为一个函数?作为使用中间件或其他地方的字典?) PS 我怎么去提出这些论点的东西 – 我需要看源?

我只需要使用快速渲染的模板语言?

我学习的节点和最简单的expression,当使用res.render('view',{data:data})呈现视图时res.render('view',{data:data})它只是一个模板引擎,如适合在视图中的玉。 我可以不使用正常的HTML?

mongoose分开的文件,而embedded架构?

我想在用户创build一个新文档之后将一个文档_id保存到另一个模式的数组中。 简而言之:用户保存一个videoURL,我想将video的文档_id保存到用户架构中的一个数组中。 我很难搞清楚如何做到这一点。 这里是我的模型文件: videos.js: // Video Model // ————- var mongoose = require('mongoose'); var Schema = mongoose.Schema; // Embedded document schema var NotesSchema = new Schema({ timecode : String, text : String }); // Main schema var VideoSchema = new Schema({ title : String, url_id : String, notes : [NotesSchema] }); module.exports = mongoose.model('Note', […]

expressJS的请求体的types

我想知道app.post('/',function(req,res))支持什么样的内容types请求req 。 我从HTML表单发送数据。 是否一定是JSON格式,还是可以直接从表单发送? 我已经从表单发送json格式的数据到服务器,但是当我访问req.body.{name attribute of inout element}它给错误无效属性的undefined。

在快递中间件中重用mongoose对象的模式

给定一个nodejs,mongoose,mongodb,expressjs设置,我们有权限/安全相关的路由来validation一个特定的请求。 例如: permissionUtils.checkStudentWritePermissions = function(req, res, next){ //load this student from the mongoose db //ensure the current user has permission to update this student } server.put("/api/student/:studentId/enroll", permissionUtils.checkStudentWritePermissions, function(req, res, next){ //load student from the database, validate the changes //update student in mongodb, send new version back to user }); 中间件很有用,因为我们确保当前用户有权在每种情况下更新学生。 (代码重用等)你会注意到,在这两个例子中,我正在从MongoDB中加载学生。 有一个可以接受的模式来避免这种双重加载? 某种请求循环caching或传递模型的stream畅方式?

带有HTTP-AUTH的node.js Express

我用http-auth模块创build基于express的node.js应用程序有问题。 这是一个可能的创build这个http-auth库的中间件我有这样的代码: //Configure Middlewares logger.configure(function() { //All output has content type json logger.use(function(req, res, next) { res.contentType('application/json'); next(); }); //Create digest auth middleware logger.use(function(req, res, next){ digest.apply(); next(); }); }); 应用这个后,当我连接到网站,我得到这个错误: TypeError: Cannot read property 'headers' of undefined 有没有解决这个问题或使用其他方法? 我需要整个应用程序的摘要validation。

Expressparsing正文或查询参数中的内容

我有一个端点接受JSON在URL或邮件正文(当然POST) app.post('/book/addBooks', function (req, res) { … 我知道来自服务器的新书JSON要么是查询参数 <server>/book/addBooks?books=[{…},{…}] 或从身体 <server>/book/addBooks 身体: books=[{…},{…}] 基本上我正在检查两个: req.body.books 要么 req.query.books 并select第一个有内容。 有没有更好的方式来expression“书籍”? 附注:在垃圾之前,你可以通过URL或身体的事实,我正在写一个模仿另一个API的服务,因为其他API允许这个垃圾,我也必须。

npm将模块安装到当前目录中,而不仅仅是node_modules

我试图创build新的项目,并做到这一点。 >expression新的项目 > cd newproject > ls app.js package.json public / routes / views / > npm安装 // … > ls app.js commander / cookie-signature / formidable / methods / node_modules / public / routes / buffer-crc32 / connect / debug / fresh / mime / package.json qs / send / bytes / cookie / […]