express

Express: How to require a file in node js express and pass a parameter value to it?

风流意气都作罢 提交于 2020-01-25 08:42:27
问题 This question has a big relation with How to require a file in node.js and pass an argument in the request method, but not to the module? -- Question. I have a node js Express app. when visitor visits http://localhost/getPosts , the main node js file requires ./routes/posts file and sends a database connection to the required file. app.use('/getPosts', require('./routes/posts')(myDatabase)); the content of ./routes/posts file is given below: var express = require('express'); var router =

How do I check if email already exists using MERN

ε祈祈猫儿з 提交于 2020-01-25 08:22:20
问题 I have a registration view and I'm trying to check whether the email already exists, I've undone the react code so you can get a good idea of the structure. The emails are set as unique in the schema. AuthController const { check, validationResult } = require("express-validator"); const jwt = require("jsonwebtoken"); const passport = require("passport"); require("../passport"); const Users = require("../models/user"); let validations = [ check("email") .isEmail() .withMessage("The email you

How to configure passport facebook using react-redux?

大兔子大兔子 提交于 2020-01-25 08:13:25
问题 I am trying to implement redux with passport facebook strategy. My action works fine i.e, it gets to the backend route and gets the data if I pass a random object. However if in the same route I try to write passport.authenticate('facebook') , it prompts me with the following error in redux: "Error: Network Error at createError (http://localhost:3000/static/js/0.chunk.js:7219:15) at XMLHttpRequest.handleError (http://localhost:3000/static/js/0.chunk.js:6762:14)" I have also initialized

Sending an Excel file from backend to frontend and download it at the frontend

故事扮演 提交于 2020-01-25 08:00:05
问题 I had created an Excel file at the backend (Express JS) using Exceljs npm module. I have it stored in a temp directory. Now I would want to send the file from the back-end to the front-end and download it there when the user clicks a button. I am struck on two things 1. How to send the file from the backend to the frontend through an HTTP POST request 2. How to then download the file in the front-end Edited content: I need the front end to be a button that appends the file to it and then

Express middleware passing variable, error 'TypeError: Cannot destructure property' in middleware function but works via route definiton

痴心易碎 提交于 2020-01-25 07:58:30
问题 I am using pug templates in express and have a layout which has my top navigation toolbar etc. Inside this layout (viewable on all routes) I want to include a count of some items in the toolbar (without having to include the request for each pages/route definition ideally). So I thought I should use middleware. I am able to use the response userProfile anywhere on the page in the /user view eg but when I try to add the const {_raw, _json, ...userProfile} = req.user; to the middleware I get

Express middleware passing variable, error 'TypeError: Cannot destructure property' in middleware function but works via route definiton

本小妞迷上赌 提交于 2020-01-25 07:58:11
问题 I am using pug templates in express and have a layout which has my top navigation toolbar etc. Inside this layout (viewable on all routes) I want to include a count of some items in the toolbar (without having to include the request for each pages/route definition ideally). So I thought I should use middleware. I am able to use the response userProfile anywhere on the page in the /user view eg but when I try to add the const {_raw, _json, ...userProfile} = req.user; to the middleware I get

Get array from response instead of Object

十年热恋 提交于 2020-01-25 07:28:07
问题 I am trying to get only specific items from my database then display it in table. This is how my sql query looks like public async aliasesListByDomain(req: Request, res: Response): Promise<void> { const { domain } = req.params; const aliases = await pool.query('SELECT * FROM virtual_aliases INNER JOIN virtual_domains ON virtual_aliases.domain_id = virtual_domains.id WHERE virtual_aliases.domain_id = ?', [domain]); if (aliases.length > 0) { res.json(aliases); } else { res.status(404).json({

Cookies are set into different domain (Node.js, Angular)

浪尽此生 提交于 2020-01-25 07:27:29
问题 I am doing web app using Angular and Node.js (Express) and I have a problem with cookies - they are set into my backend domain instead of my frontend. When I make a POST request to /auth endpoint , server will return HttpOnly cookies - one is JWT and the second is refresh token. When I inspect network tab in chrome, I can see that server sent these cookies back, but when I inspect Application > Storage > Cookies, nothing is here. I find out, that cookies are set on my backend domain. (app

CORS with google oauth

て烟熏妆下的殇ゞ 提交于 2020-01-25 07:18:47
问题 I'm trying to implement google login in my app and I ran into a frustrating problem. I have my react app running on port 3000 and my express server is on port 5000. I'm also using passport to authenticate users. When I'm trying to login via google and I hit the route bellow I'm get the error No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. From what I read, I have to set up CORS on the express server

CORS with google oauth

泄露秘密 提交于 2020-01-25 07:17:08
问题 I'm trying to implement google login in my app and I ran into a frustrating problem. I have my react app running on port 3000 and my express server is on port 5000. I'm also using passport to authenticate users. When I'm trying to login via google and I hit the route bellow I'm get the error No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. From what I read, I have to set up CORS on the express server