node.js

mongoose populate in array of custom objects

主宰稳场 提交于 2021-02-11 14:42:28
问题 In the user model, I have an array of custom objects followedPlaylists which contains two attributes ( playlist: the id of the playlist, public: to determine whether it is public or not) as shown below const userSchema = new mongoose.Schema({ ..... other attributes followedPlaylists: [{ playlist: { type: mongoose.Schema.ObjectId, ref: 'Playlist', unique: true }, public: Boolean }] }) I want to populate on followedPlaylists.playlist so the response would be something like [{ playlist: * the

Waterfall prompt using activity.text instead of actually prompting user

我们两清 提交于 2021-02-11 14:42:25
问题 I have a dialog where a prompt in the first step is getting skipped. I determined that what is happening is that somehow step.context.activity.text is automatically being interpreted as the prompt response. For example, if I trigger the dialog with "Expedite my order", step.context.activity.text in the first step is "Expedite my order", the prompt is skipped, and step.result in the next step is "Expedite my order". I tried creating a "buffer step" as step 1 that just did return await step

Express.js Csurf working in postman but not React.js

自作多情 提交于 2021-02-11 14:41:20
问题 I'm trying to setup CSRF tokens so that I can do a number of checks before issueing a token to the client to use in future requests. Taking the guidance from the csurf documentation, I've setup my express route with the following: const express = require('express'); const router = express.Router({mergeParams: true}); const csurf = require('csurf'); const bodyParser = require('body-parser'); const parseForm = bodyParser.urlencoded({ extended: false }); const ErrorClass = require('../classes

node.js and AWS Lambda Function continue function execution after callback

若如初见. 提交于 2021-02-11 14:41:16
问题 I am trying to use a lambda function to alter a database and then send a push notification. I don't want to wait for the push notification server to reply. In the occasional case that the push notification is unsuccessful, that is not a concern. It is more important that the function executes in a timely manner. Currently I'm using the following two functions. Everything works as expected except that there doesn't seem to be any time saving. ie, when there is no device token and push is not

How can I delete a file with multer gridfs storage?

好久不见. 提交于 2021-02-11 14:37:49
问题 The following code works as expected to upload and retrieve files: // Mongo URI const mongoURI = 'mongodbconnstring'; // // Create mongo connection const conn = mongoose.createConnection(mongoURI); // // Init gfs let gfs; conn.once('open', () => { gfs = new mongoose.mongo.GridFSBucket(conn.db, { bucketName: 'Uploads' }); }); // Create storage engine const storage = new GridFsStorage({ url: mongoURI, file: (req, file) => { return new Promise((resolve, reject) => { const filename = file

How can I delete a file with multer gridfs storage?

老子叫甜甜 提交于 2021-02-11 14:35:05
问题 The following code works as expected to upload and retrieve files: // Mongo URI const mongoURI = 'mongodbconnstring'; // // Create mongo connection const conn = mongoose.createConnection(mongoURI); // // Init gfs let gfs; conn.once('open', () => { gfs = new mongoose.mongo.GridFSBucket(conn.db, { bucketName: 'Uploads' }); }); // Create storage engine const storage = new GridFsStorage({ url: mongoURI, file: (req, file) => { return new Promise((resolve, reject) => { const filename = file

AWS Lambda doesn't recognize NODE_EXTRA_CA_CERTS

六眼飞鱼酱① 提交于 2021-02-11 14:33:05
问题 I'm using the serverless framework and I'm trying to reference a bundled certificate in a lambda function for some API calls. Locally, when setting and pointing NODE_EXTRA_CA_CERTS to my cert, everything works as it should. I've configured an environment variable for NODE_EXTRA_CA_CERTS with my lambda and point it to the bundled cert as follows in my serverless.yml , but the AWS node environment doesn't pick it up: provider: name: aws region: us-east-2 runtime: nodejs12.x endpointType:

Node | Require is not defined [duplicate]

前提是你 提交于 2021-02-11 14:32:35
问题 This question already has answers here : Client on Node.js: Uncaught ReferenceError: require is not defined (8 answers) Closed 2 years ago . Edit : Problem solved using webpack For the needs of an API, I needed to import MD5 and moment . I downloaded the packages using the basic npm install but when I try to import it on my app.js using the code below : const md5 = require ('./node_modules/md5/md5.js'); const moment = require ('./node_modules/moment/moment.js'); function getTimeStamp () {

POST API call returns CORS error without https and ERR_CONNECTION_CLOSED without

有些话、适合烂在心里 提交于 2021-02-11 14:32:26
问题 I have a simple Javascript application that should be able to save a json file to the server. This is my nodejs server: var express = require("express"); var multer = require('multer'); var app = express(); var storage = multer.diskStorage({ destination: function (req, file, callback) { callback(null, './data'); }, filename: function (req, file, callback) { callback(null, file.fieldname + '-' + Date.now()); } }); var upload = multer({ storage : storage}).single('userPhoto'); app.get('/'

Firebase Cloud Functions get data on real time database onCreate

不打扰是莪最后的温柔 提交于 2021-02-11 14:31:07
问题 const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(); exports.sendNotification = functions.database.ref('/messages/diyetisyen/{uname}/{msgid}/message') .onCreate((snapshot, context) => { let message = snapshot.val(); let uname = context.params.uname; let root = snapshot.ref.root; let token = root.child('/users/' + uname + '/token').ref.token; let payload = { data: { custom_notification: JSON.stringify({ body: message + '', title: