Tag: 表示

获取喜欢的post的ID – Node.js Express Socket.io

我试图build立一个职位系统,人们可以评论和喜欢。 这就是我现在所做的 <!– posts.ejs –> <% posts.forEach(function(task) { %> <%- include post.ejs %> <% }) %> 当有人喜欢,我使用这样的sockets <!– post.ejs –> <script> var socket = io('localhost:48001'); $('#like').on('click', function(event){ var task = <% task._id %> console.log(task); var liker = { pId: task , usr: user._id, liker: 1 }; socket.emit('like', liker, function(response){ if(response==true){ //console.log("blue"); } }); }); //server […]

将多个AngularJS Post请求发送到Express服务器? 服务器崩溃的第二个post请求

所以鉴于我不能同时在我的客户端运行这两个post请求,我试图在第一篇文章的.then部分运行第二篇文章。 这对我的其他项目一直工作得很好。 但由于某种原因,当第二个职位请求触发我的服务器不答复。 当我检查服务器的控制台时,我发现它崩溃,并有一个错误消息(在这篇文章的底部)。 什么可能导致这个? 我已经在我的服务器代码中的第二个发布请求中放置了断点,并且注意到断点甚至没有被触发。 服务器在命中之前崩溃,并让我select继续。 客户端代码(当用户按下button时被触发): $scope.searchCharacter = function(){ var request = {name: $scope.charName, realm: $scope.selectedRealm}; //First post request $http.post('/searchCharacter', request) .then(function(response) { //sets some variables var id = 0; //Second post request $http.post('/helloworld', id) .then(function(response) { //sets some more variables debugger; }); }); } 服务器代码: //First post request app.post('/searchCharacter', jsonParser, function (req, […]

Nodejs + Google-Cloud-Storage – 无法读取未定义的属性存储

我试图通过导航到/上传路线以用户身份上传图像。 使用Muller和谷歌云存储 但是,我不能访问函数sendUploadToGCS中的存储对象,它返回undefined。 为什么会这样,我只能认为它可能与使用它作为一个中间件有关,如果这种情况是可能达到相同的,而不使用中间件的multer和gcs,我更喜欢简单的asynchronous/承诺。 app.js let multer = require('multer'); let m = multer({ storage: multer.MemoryStorage, }); let GoogleCloudStorage = require('./modules/google/google-cloud-storage'); let storage = new GoogleCloudStorage(); app.use('/upload', m.single('avatar'), storage.sendUploadToGCS, (req, res) => { console.log(req.file); return res.json('1'); }); 谷歌云,storage.js let Config = require('../../config/app'); let Storage = require('@google-cloud/storage'); class GoogleCloudStorage { constructor() { this.bucketName = Config.filesystem.google.bucket; this.storage = […]

login生产最佳实践?

在生产模式下使用morgan作为logging器,还是把它扔掉,只用于开发模式? login生产模式的最佳做法是什么?

问题与委托和expressionpath

我目前正在从事一些大学课程,这本质上是一个用快递写的API。 只要遵循规范,我们就可以使用其他软件包。 我试图使用委托自动加载我的模型,中间件和路线。 我面临的问题是我们必须遵循的文件夹结构。 coursework |– artifact | |– server | | |– api | | | |– models | | | | `– stories.js | | | |– middleware | | | | `– stories.js | | | `– routers | | | `– stories.js | | |– node_modules | | |– package.json | […]

Express导出类中的箭头函数 – 意外的令牌

我有我的类,我输出和快递和节点使用的文件。 我想使用箭头function,这是一个例子: class MyClass { myFunc(arg) { console.log(arg); } myArrowFunc = (arg1, arg2) => { console.log(arg1); console.log(arg2); }; } module.exports = { MyClass } 一切工作正常之前添加myArrowFunc。 之后,运行应用程序后,我有一个错误: myArrowFunc = (arg1, arg2) => { ^ SyntaxError: Unexpected token = 我的节点版本是9.x所以它应该工作…或者我忘了一些事情。

每个节点模块中的请求variables? (快速查看帮手)

我正在研究这个项目https://github.com/tanema/express-helpers ,我分叉了固定起来,并增加了新的function。 我想要做的,而不是必须使用form_tag_end()甚至end_tag('标记名')我只想使用一个end()方法。 为了这个工作,我需要某种堆栈实现,当一个开始标签被发送到堆栈等。 我不能只在名为tagStack的模块中创build一个variables,只是使用它,因为它会创build一个竞争条件,在这个条件下两个请求同时使用模块,并且堆栈顺序变得混乱。 我在想如果有一些方法来访问请求variables,我只是把它存储在那,并删除variables如果是空的,但我不知道如何做到这一点。 有什么build议么?

Node.js中的Handlebars.js,缺lessparsing器

我试图在节点中包含Handlebars.js 。 在base.js文件中,它需要一个名为parser的文件: var handlebars = require("./parser").parser; 这个文件似乎没有包含在软件包中。 这应该是以某种方式生成的? 更新:我想我明白了。 我需要使用包含的ruby文件进行编译。 从来没有使用ruby,让我看看如果我可以得到这个Rakefile的工作。 -谢谢

Express Node.js框架:如何通过replace一个命名的参数段来重新编写一个URL?

在我的Express应用程序中,当路线中的某些参数符合某些条件时,我想使用路线参数前提条件执行一些redirect。 作为一个例子,假设我希望将参数word转换为全部大写,如果还没有的话。 参数word可能出现在几个不同的路由中,例如/:word , /foo/:word , /foo/:word/bar等等。幸运的是,在路由参数前提下,例如(CoffeeScript中的代码): app.param 'word', (req, res, next, word) -> if word isnt word.toUpperCase() new_URL = // current URL, but replace word with word.toUpperCase() // res.redirect new_URL, 301 我的问题是关于如何构造new_URL ,用它的大写等价物replace:word 。 我希望能够使用相同的函数构造new_URL ,而不pipe当前正在使用哪条path。 我看到有req.route ,但没有定义。 我想我可以通过req.app.routes.routes.get[req._route_index]访问当前匹配的路由,然后拆分path ,并重新构build它,但似乎过于复杂。 有没有办法简单地迭代当前路线的path段? 谢谢!

mongoose – 用embedded文件保存模型的表单

无法将embedded式数组保存到Mongoose模型。 请参阅底部的编辑。 我有一个表单,使用Mongoose在Express中创buildBlogPost,以将数据存储在mongo中。 我可以创build和查看新的博客post,但是我只是在BlogPost模型中添加了一个embedded式文档模式Feed,并且无法让Feed数组从模板保存到模型中 码: BlogPosts.js var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/my_database'); var Schema = mongoose.Schema , ObjectId = Schema.ObjectId; var Feeds = new Schema({ name : { type: String } , key : { type: String } }); var BlogPost = new Schema({ author : ObjectId , title : { type: String, required: true, index: […]