express

Why am I unable to send response object of Express through SocketIO?

ぃ、小莉子 提交于 2021-01-29 10:42:00
问题 I'm trying to send the response to an express request by sending it to a ws client and wait for its response. So I need to send the res object to the client (I couldn't find another way). Here is what I did: var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http); app.get('/', (req, res) => { res.sendFile(__dirname + '/index.html'); }); io.on('connection', (socket) => { socket.on('res', (e) => { e.res.send(e.data) }) }) app.get('/endpoint',

Express render view and download file at the same time

て烟熏妆下的殇ゞ 提交于 2021-01-29 09:39:38
问题 I would like to use express to render a file AND download a file at the same time My current code is as follows: res.attachment('filename.csv'); res.render('pages/result', { data }); However, if I do this, it only downloads the data and does not render the view What I want is to render a success page, and then send the file so that it downloads I need this to be done with 1 endpoint, because, I need to generate the file and only if it is successful, I would render the success page Am I able

Socket.io and express app not connecting due to CORS error: “The value of the 'Access-Control-Allow-Origin' header must not be the wildcard '*'”

放肆的年华 提交于 2021-01-29 09:25:51
问题 I'm slowly losing my mind over a very stupid issue I'm having. I have a socket.io/express app uploaded to Digital Ocean as a Docker setup. To allow https, I am using caddy as part of my Docker setup to allow for automatic https. I've been trying to connect to this setup via my domain and from my local React app that lives on localhost:3000. But I am constantly getting the following error: Access to XMLHttpRequest at 'https://mediaserver.domain.dev/socket.io/?EIO=3&transport=polling&t=N5BXNK2'

node js - get url params from original base url

本小妞迷上赌 提交于 2021-01-29 09:07:25
问题 In my node JS express app I have defined routes with path having regex expressions in my app.js file. i.e var tableRoute = require('./routes/tables'); app.use('/keyspaces/(regex to match param)/tables',tableRoute); Then in my routes/tables.js file I have following handler defined for this route router.get('/', function(req, res, next) { // need to access url param here }); Now clearly I cannot access my url param via req.params.xzy because here handler is defined for '/' not for '/keyspaces/

Where does next() go in Express js?

强颜欢笑 提交于 2021-01-29 09:02:17
问题 I'm new to javascript, nodejs, and express, and confused of using next() . I want my code to move on to the next router with next() , but it seems to move on to the next then . My code: //validation router.post('/requests', (req, res, next) => { let {myData} = req.body basicCheck(res, cluster, myData) .then(() => { if (myCheck()) { next() return // Doesn't need to do rest of the code. Just move on to the next router.post } ... return Promise.all(somePromises) }) .then(() => { ... return

Axios POST isn't running inside NodeJS/Express Route

十年热恋 提交于 2021-01-29 08:55:45
问题 I'm calling my express route (domain.com/api) from another domain (domain1.com). So I've set up Express to accept POST requests to the route /api and signing a JWT before exchanging the JWT via Axios for a Bearer access token. I cannot seem to get the Axios post request to fire. Is is possible it's a firewall thing? How can I see where the error lives? Forgive me, I'm still new to Node/Express. Here is my pertinent code: const express = require('express'); const cors = require("cors"); const

MariaDB connection to ExpressJS access denied no password error

那年仲夏 提交于 2021-01-29 08:40:52
问题 I'm trying to connect an Express app to MariaDB, both running on localhost. I have the following code in an Express app: const mariadb = require('mariadb'); const pool = mariadb.createPool({ user: 'testuser', password: 'password', database: 'test', connectionLimit: 5 }); I can connect using 'testuser' from the MariaDB command line, but when Express executes the code above, I see the following in the console: SQLError: (conn=63, no: 1698, SQLState: 28000) Access denied for user 'testuser'@

AngularUniversal prerendering error: UnhandledPromiseRejectionWarning: Error: No NgModule metadata found for 'class{}'

天涯浪子 提交于 2021-01-29 08:33:21
问题 Goal Question looks long winded - it's not! I'm using Angular Universal to implement SSR, following this tutorial. Universal/express-engine is installed, main.js is generated in the dist/projectname/server folder, and I've created a prerender.js folder in the project root. Problem When I try npm run prerender it starts work prerendering until eventually hitting the following error: Prerendering 5 route(s) to C:\Users\odubh\Documents\Personal_Web_Projects\Hibernio.com\Hibernio0.3\hibernio\dist

How to add static file from `node_modules` after declare the `public` as static in express?

不羁的心 提交于 2021-01-29 08:27:13
问题 In my express app, I am keeping the below config: var express = require("express"); var path = require("path"); var jsonServer = require("json-server"); var app = express( ); app.use(express.static('public')); app.get("/", function( req, res ) { res.sendFile( express.static( path.join(__dirname, "/public/index.html" ) ) ); }); app.use('/api', jsonServer.router('./db.json')); app.listen( 3000 ); All this is works fine. the problem is, I am not able to add the jquery from node_modules . here is

Req.body is empty when I POST using axios but when I use 'request' it's working fine

不羁的心 提交于 2021-01-29 08:21:02
问题 A little background - I have my NodeJS server running on port 3001 and my React application on port 3000. I've set up a proxy in my React application package.json to proxy all requests to port 3001 - "proxy": "http://localhost:3001" Now when I'm using Axios in my React application to make POST request on 'users/authentication' route on my NodeJS server, the request body is being parsed as blank on the Node server const request = { method: 'POST', url: `/users/authenticate`, headers: {