express

Array.push does not seem to work on MongoDB

杀马特。学长 韩版系。学妹 提交于 2021-01-28 02:22:21
问题 I would like to create a dynamic vector/array in MongoDB. The idea is simple: whenever someone submits something, it should update a user in my database in MongoDB. I have created a variable for that. I have already tested: the proper user is found correctly. Please, find it a snippet of my code. User.findOne({ name }) .then(user => { user.something.push(something to push); }) I have set the default value when it is created as empty: something: { type: [String], default: [] } However, it does

Cross-Origin Request Blocked when requesting Paypal sandbox but a different localhost port works fine

匆匆过客 提交于 2021-01-28 00:47:37
问题 I'm having trouble understanding why I'm getting a Cross-Origin Request Blocked error when trying to send a user in my app to a sandbox.paypal.com payment page when ordering a product. The frontend of my app (with React) uses localhost port 3000 while the backend uses localhost port 4000. The communication between the two ports when performing CRUD operations works as intended. But now that I'm introducing paypal into the mix the app doesn't go to the sandbox paypal page when trying to order

Migrating Express application to NestJS

故事扮演 提交于 2021-01-27 20:30:13
问题 I have an existing express application, and it is large enough. I want to migrate it to NestJS application, but do it step by step. So I have created Nest app with an existed Express instance, by faced a problem - all nest handlers always add after Express handlers. But I have a root Express middleware I want to apply only for some handlers that go after it. How can I apply Nest handlers before Express handlers? For example. I created a new NestJS project, and changed main.ts import {

pass params from app.js to route.js

时间秒杀一切 提交于 2021-01-27 19:52:30
问题 I have app.js with the following code and I've additional file which is called router.js which handle request's such post/read/etc this is the app.js var express = require('express'); module.exports = function () { var app = express(); .... require('./router/routes')(app, express); return app; }; The router.js is looks like following */ module.exports = function (app, express) { var appRouter = express.Router(); app.use(appRouter); appRouter.route('*') .post(function (req, res) { handler

Which command should I use to minify and optimize nodejs express application?

不问归期 提交于 2021-01-27 19:51:31
问题 I am ready with an Express-generator sccafold website and need to publish it. Which command should I use to minify files and be optimized for publishing? And also, what are the directories should I take to upload? 回答1: express-generator is a server rendering framework based on express framework, not a client side rendering like react, vue, angular, etc in which a minify process is very common. This question: Does it make sense to minify code used in NodeJS? indicates me that nodejs is already

express-fileupload to Google Drive API

混江龙づ霸主 提交于 2021-01-27 19:43:00
问题 I can successfully save my uploaded image in my public uploads folder and integrate google drive api but it seems that it is uploading an empty file. What should I put in the body parameter of the Google Drive API from my req.files data {name: 'country.jpg',data: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 00 48 00 48 00 00 ff ed 26 0c 50 68 6f 74 6f 73 68 6f 70 20 33 2e 30 00 38 42 49 4d 04 04 00 00 00 00 00 22 ... 246290 more bytes>,size: 246340,encoding: '7bit',tempFilePath: ''

user.setPassword is not a function - passport local mongoose

本秂侑毒 提交于 2021-01-27 19:06:21
问题 I am implementing a reset password feature on for the users of my website. However, it seems to throw this error when the user confirms new password at the reset.ejs page. The following steps are being performed correctly: Token sent on mail When clicked on token, new password page opens When user enters new password and confirm new password and hits the button to save the new password, the function in users.js user.setPassword does not work as the error is mentioned below. It is a built in

express parsing all request to json

守給你的承諾、 提交于 2021-01-27 18:54:55
问题 I am started to implement some API to my marketplace. I am using Shoppy.gg for get some cryptopayments. And i have got a problem about the verify their callbacks from my back end. In their documentation explain to how validate shoppy with php: $signature = hash_hmac('sha512', file_get_contents('php://input'), 'secret'); $is_valid = hash_equals($signature, $_SERVER['HTTP_X_SHOPPY_SIGNATURE']); And i am trying to do it with nodejs express module const signature = req.header('x-shoppy-signature'

How to clear req.session on clearing browser cookies in node js?

匆匆过客 提交于 2021-01-27 18:53:42
问题 I am using "express": "~4.14.0" with express-session for saving username. Once the user is logged in, I will save the user name in req.session.authorizedUser = username to display it in the application header. When either the browser history is cleared or the browser is closed, I want to clear the session. Please suggest me if there is any way to clear the session when doing any of these two operations. I have tried setting the maxAge option for session cookies, as shown below, but it doesn't

Multer image upload in Nodejs and Express

谁说我不能喝 提交于 2021-01-27 18:41:11
问题 I've been trying for days to upload an image using Multer. This is how far I got. I tried multiple things, and can't seem to make it work. I don't know how to use Multer to upload an image in my createUser function in the format shown below. My ' server.js ' file: var express = require('express'); var multer = require('multer'); var upload = multer({dest: 'uploads/'}); var router = require('./app/routes'); var bodyParser = require('body-parser'); var mongoose = require('mongoose'); var