express

Sails 0.10 req.files empty on file upload

血红的双手。 提交于 2020-01-05 12:14:09
问题 I'm doing a file upload to sails v0.10 via POST /file/upload HTTP/1.1 Host: localhost:1337 Cache-Control: no-cache but the req.files object remains empty in sails upload: function(req,res) { console.log(req.files); // {} } in my file controller. What am I doing wrong? Thanks! 回答1: One should know that since sails v0.10-rc6 the Skipper-middleware is automatically used, so if you're having the same issue, don't use 'req.files' anymore but use the req.file('name') function (https://github.com

Store an instance in Express js session

不想你离开。 提交于 2020-01-05 10:26:09
问题 I'm using the expressjs session, and I have a instance need to store: function a(){this.name="";} var ins = new a(); req.session['user'] = ins; and when I get res.session['user'] next time, the object is not instanceof a, and it cannot access any prototype methods in a, how can i store the ref of the object in session, looks the session will convert it to json object 回答1: You can't store instances like that in JSON unless: You provide your own custom serializer (implementing a toJSON()

Invalid ELF header Node js with couchbase db

一笑奈何 提交于 2020-01-05 10:05:33
问题 I've seen a handful of posts about this issue but the results all seem to be specific to the users configuration. I'm using couchbase db with a express js server. When I run the code locally (windows) it works fine. The database it self is hosted on a linux server. When I deploy the code to our testing environment ( linux ), I'm getting this error when I try to run "node server.js": /var/www/html/BTRnode/node_modules/couchbase/node_modules/bindings/bindings.js:83 throw 8 Error: /var/www/html

How to register a User in Firebase using Node.js?

ぃ、小莉子 提交于 2020-01-05 08:37:31
问题 PROBLEM: 0) The user is created in the auth system in Firebase (I see it in the Auth tab), 1) But no changes are made to the database. 2) The page seems to be stuck infinitely loading. 3) Only "Started 1..." is logged to the console. CODE: router.post('/register', function(req, res, next) { var username = req.body.username; var email = req.body.email; var password = req.body.password; var password2 = req.body.password2; // Validation req.checkBody('username', 'Username is required').notEmpty(

Coffeescript + Express: unexpected ,

只谈情不闲聊 提交于 2020-01-05 08:26:34
问题 I'm learning to make an app on Express.js using Coffeescript. I have uploaded my code at: https://github.com/findjashua/contactlist When I try to run the app, I get the following error: app.coffee:11:24: error: unexpected , res.send 'Hello World' ^ I don't understand the issue here. Any ideas? 回答1: On line 11 in contacts.coffee you have exports.index = (req, res) -> ContactModel.find (err, contacts), -> if not err remove that comma on the central line, after contacts) . 来源: https:/

error: input is self closing and should not have content

会有一股神秘感。 提交于 2020-01-05 08:24:31
问题 I'm trying to pick up some Jade to use with express, and I'm having trouble understanding why I'm getting this error. The whole of my .jade file is: .login #register div(style='float:right') p input.loginInput (type='text', name='user') p input.loginInput (type='password', name='pass') p input#button.loginInput (type='submit', value='Join') div(style='text-align:right;padding-right:110px;padding-top:3px;') p IGN: p Password: a(href='#' onclick='getProfileLogin()') < Back I'm getting the above

angularjs reuse template and bind to different properties within the same scope

邮差的信 提交于 2020-01-05 08:09:51
问题 I'd like to reuse an express included template multiple times and selectively bind it to different properties of the scope as follows: <div ng-show="isCoApplicant" bind-to="applicant in data.coApplicant"> <% include ../row-templates/applicant-row %> </div> Similar to the behavior of ng-repeat which creates a child scope for the row and sets a property on it according to the expression 'applicant in data.coApplicant', and the row inputs can be bound to 'applicant' via ng-model. I've spent some

Pre-populating HTML/Jade from Express/node.js web app

谁说我不能喝 提交于 2020-01-05 07:27:40
问题 I have a web app that is built using Express for node.js. I'm using Jade template files for the HTML displays. In one of these displays I'd like to have the various fields pre-populated with data. The data is being stored in a mongodb session store, as well as in a separate collection in the db. I'd prefer to use the session data to pre-populate these fields in the HTML/Jade displays. How can I go about doing this (if it's possible)? 回答1: Add the defaults to res.locals and then set the input

Sum of subdocuments in Mongoose

北战南征 提交于 2020-01-05 07:19:09
问题 Currently I have this schema. var cartSchema = new Schema({ userPurchased: {type: Schema.Types.ObjectId, ref: 'users'}, products: [ { product: {type: Schema.Types.ObjectId, ref: 'products'}, size: {type: String, required: true}, quantity: {type: Number, required: true}, subTotal: {type: Number, required: true} } ], totalPrice: {type: Number, default: 0, required: true} }); Example of db record { "_id": { "$oid": "586f4be94d3e481378469a08" }, "userPurchased": { "$oid":

Node JS res.sendFile() not working

做~自己de王妃 提交于 2020-01-05 07:18:35
问题 I'm getting ReferenceError: main is not defined when I open up the http://localhost:3000/ Here I try to open up the main.html located in views directory This is my app.js const express = require('express'), app = express(), config = require('./config/index'), routes = require('./routes/route'); app.use(express.static(`${__dirname}/public`)); app.use(express.static(`${__dirname}/views`)); app.use('/',routes); app.listen(config.port,()=>{ console.log(`Listing at port ${config.port}`)}) This is