node.js

UserState showing null in onMembersAdded function

爷,独闯天下 提交于 2021-02-10 14:48:23
问题 I have logic in my onMembersAdded function to load the user state and see if userData.accountNumber attribute exists. If it does not, a run an auth dialog to get the user's account number. If the attribute does exist, the welcome message should be displayed without a prompt. When I test on local, this works fine. But when I test on Azure, I always end up in the !userData.accountNumber block. Through checking the console log, I can see that in the onMembersAdded function is showing {} for the

Heroku-deployed Django webpage doesn't update when DB changes

有些话、适合烂在心里 提交于 2021-02-10 14:42:15
问题 I have deployed an app in Heroku using Django. The Django program uses a SQLite database db.sqlite3 on root directory to populate its page. Separately, there is also a Node.js scraper program that inserts to that database. The problem is that the hard-refreshed webpage shows the same data even after the content of the database changed. Curiously, this does not happen when it is tested locally with python manage.py runserver . How can I fix this problem? Thank you in advance! For reference,

how to save an image from discord using discord bot node js

微笑、不失礼 提交于 2021-02-10 14:41:55
问题 So far I've only been able to get text and links from what other people on my discord channel type, but I want to be able to save posted images/gifs. is there any way I can do this through the bot or is it impossible? I'm using discord.js. 回答1: Images in Discord.js come in the form of MessageAttachments via Message#attachments . By looping through the amount of attachments, we can retrieve the raw file via MessageAttachment#attachment and the file type using MessageAttachment#name. Then, we

nodemon app crashed - waiting for file changes before starting… nodejs

我的梦境 提交于 2021-02-10 14:39:45
问题 file is not uploading in nodejs it shows error which is: nodemon app crashed - waiting for file changes before starting... nodejs code: var path = require('path'); var express = require('express'); var multer = require('multer'); var app = express(); var Storage = multer.diskStorage({ destination: './public/uploads/', filename: (req, file, cb) => { cb(null, file.fieldname+"-"+Date.now()+path.extname(file.orignalname)); } }) var upload = multer({ storage: Storage }).single('file'); app.use

Need to push data in nested subdocument array

心不动则不痛 提交于 2021-02-10 14:37:53
问题 I need to push data in nested subdocument array(replyComment): This is an example of a document from my database: { comments: [ { replyComment: [], _id: 601a673735644c83e0aa1be3, username: 'xyz123@gmail.com', email: 'xyz213@gmail.com', comment: 'test123' }, { replyComment: [], _id: 601a6c94d1653c618c75ceae, username: 'xyz123@gmail.com', email: 'xyz123@gmail.com', comment: 'reply test' } ], _id: 601a3b8038b13e70405cf9ea, title: 'latest test', snippet: 'latest test snippet', body: 'latest test

How to use a native node.js addon in React

白昼怎懂夜的黑 提交于 2021-02-10 14:25:44
问题 I have a react project in which I would like to use this native node.js addon, which is a wrapper for a C++ SDK. I've successfully used this module in the past within an Electron project, and can run the sample successfully with node as well. My question is how I would be able to use this in React, or write my own React friendly solution using the C++ SDK. I've tried to clone the module and place it under a lib folder in my react project, I ran npm install within that folder to install it's

Error in Promise Not sending any error in response object in NodeJS/Express/Mongoose

让人想犯罪 __ 提交于 2021-02-10 14:24:09
问题 I am trying to convert old mongoose promise code to Native ES6 Promise. I am getting all the errors thrown in catch and I can log it in console but when I try to pass it to response object I get empty object. Following is my code module.exports.login = function(req, res) { var userPromise = User.findOne({email:req.body.email}).exec(); userPromise.then(function(user) { if(!user){ throw new Error("step 1 failed!"); } }) .then(function(user) { if(!user.comparePassword(req.body.password)){ throw

Error in Promise Not sending any error in response object in NodeJS/Express/Mongoose

江枫思渺然 提交于 2021-02-10 14:23:40
问题 I am trying to convert old mongoose promise code to Native ES6 Promise. I am getting all the errors thrown in catch and I can log it in console but when I try to pass it to response object I get empty object. Following is my code module.exports.login = function(req, res) { var userPromise = User.findOne({email:req.body.email}).exec(); userPromise.then(function(user) { if(!user){ throw new Error("step 1 failed!"); } }) .then(function(user) { if(!user.comparePassword(req.body.password)){ throw

Error building with ng build --prod. Fine without --prod flag and ng serve

痴心易碎 提交于 2021-02-10 14:23:33
问题 I have a project that built fine with ng build --prod until I upgraded the version of TypeScript from 2.72 to 2.92 in my package.json. After upgrading, I now get the following error: ERROR in Cannot read property 'Symbol(Symbol.iterator)' of undefined However, the project builds fine using ng build and runs fine using ng serve so I have no idea where this problem is occurring and the error doesn't tell me where the problem is in my project. 回答1: I found the issue. Using resolveJsonModule

What is the best way to multiple file upload through a single input in nodejs express 4?

前提是你 提交于 2021-02-10 14:21:18
问题 I'm using nodejs with express 4. I'm trying to upload multiple file through a single input field. Also I submit my form through ajax. I'm using express-fileupload middleware for uploading files. When i upload multiple files, it works fine. But when upload a single file, it's not working. html code- <input type="file" name="attach_file" id="msg_file" multiple /> ajax code- var data = new FormData(); $.each($('#msg_file')[0].files, function(i, file) { data.append('attach_file', file); }); $