express

React + Express: Proxy error: Could not proxy request /total from localhstem_errors

余生颓废 提交于 2021-02-10 14:56:19
问题 This is a follow-up question from my previous question React.js: Axois Post stay on pending(but i am getting data) My package.json file { "name": "my-app", "version": "0.1.0", "private": true, "dependencies": { "axios": "^0.18.0", "bootstrap": "^4.1.3", "express": "^4.16.3", "mongodb": "^3.1.6", "react": "^16.5.2", "react-dom": "^16.5.2", "react-html-parser": "^2.0.2", "react-router-dom": "^4.3.1", "react-scripts": "1.1.5", "reactstrap": "^6.4.0" }, "scripts": { "start": "react-scripts start"

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

Apollo Server Express: Request entity too large

风格不统一 提交于 2021-02-10 14:25:48
问题 I need to POST a large payload in a GraphQL mutation. How do I increase the body size limit of Apollo Server? I'm using apollo-server-express version 2.9.3. My code (simplified): const myGraphQLSchema = new GraphQLSchema({ query: new GraphQLObjectType({ name: 'Query', fields: { user: UserQuery, }, }), mutation: new GraphQLObjectType({ name: 'Mutation', fields: () => ({ ...UserMutations, }), }), }); const apolloServer = new ApolloServer(schema: myGraphQLSchema); const app = express(); app.use

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

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); }); $

How to check the response from global fetch in JEST test case

自闭症网瘾萝莉.ら 提交于 2021-02-10 14:18:43
问题 So, i am using jest for testing my node function which is calling fetch() APi to get the data, now when I am writing the test cases for the same i am getting an error like : expect(received).resolves.toEqual() Matcher error: received value must be a promise Received has type: function Received has value: [Function mockConstructor] my function : export function dataHandler (req, res, next) { const url= "someURL" if (url ) { return fetch(url ) .then((response) => response.json()) .then(

Req.body is empty node.js and express

柔情痞子 提交于 2021-02-10 14:14:12
问题 I am trying to send a string from a client side page to a server, but the server receives an empty object. Here is my client side code: fetch("/sugestions/sugestions.txt", { method: "POST", body: JSON.stringify({ info: "Some data" }), headers: { "Content-Type": "application/json; charset=utf-8" } }) .then(res => { if (res.ok) console.log("Yay it worked!"); else window.alert("Uh oh. Something went wrong!\n" + res); }); This is my server side code: const express = require("express"); const url

`Extensions` field not shown in apollo graphql response data

我们两清 提交于 2021-02-10 13:20:30
问题 Here is a reproducible example. Run app.js and navigate the playground at http://localhost:4000/graphql You can run queries like: query RecipeQuery{ recipe(title:"Recipe 2"){ description } } Problem: I need debugging information from the extensions field in the response data. I'm talking about this extensions field: "data":{....}, "extensions": { "tracing": {} "cacheControl":{} } But in reality, I'm only getting the data field: "data":{....} I have already enabled tracing and cacheControl in

How to send form data to server

谁说我不能喝 提交于 2021-02-10 13:17:27
问题 I want to build a small website. I have backend almost done but i can't find how can i send form data to server. Here is my attempt and i want to send the data to localhost running at port 3000 for example: jQuery('#signUp-Form').on('submit',function(e){ e.preventDefault(); console.log('Sending data'); var name = jQuery('[name = username]').val(); // socket.emit('sign-up',{ // username: jQuery('[name = username]').val(), // password: jQuery('[name = password]').val() // }); }); I can do with