express

How to output a PDF buffer to browser using NodeJS?

北战南征 提交于 2020-07-20 20:33:13
问题 So I am using html-pdf to convert my html and here is my code: var pdf = require('html-pdf') var html = 'somehtmlfile.html' pdf.create(html).toBuffer(function (err, buffer) { if (err) { console.log(err) } else { console.log(buffer) var pdfBuffer = new Buffer(buffer) res.setHeader('Content-disposition', 'inline; filename="test.pdf"'); res.setHeader('Content-type', 'application/pdf'); res.send(pdfBuffer) } } I am not getting any PDF file to be downloader nor any output of a pdf file in the

Firebase Functions HTTPS 403 Forbidden

北慕城南 提交于 2020-07-20 07:50:30
问题 I built a Firebase HTTP Event function with Node and Express. The function is working, but when I invoke the function on the client side I get 403 Forbidden . The first time I invoked the function I was asked to sign in with a Google account. I signed in with the same account I use for Firebase, but when I invoked the function I got: Screenshot of 403 error I looked at the use roles on Google cloud platform and the permission to invoke the function is set to allUsers . I signed out and back

Socket.io with multiple namespaces?

孤人 提交于 2020-07-19 05:09:47
问题 I have a route that listens to a particular route id. /** * Chat app routes. */ app.get('/games/:id', gameChatController.chatRoom); Based on the route id I can determine what game the chat is about. My question is how do I use this to pass into socket.io? bin/www /* * setup socket.io, and socket-session */ var socketIO = require('socket.io'); var io = socketIO(server); var SessionSocket = require('session.socket.io'); var sessionSockets = new SessionSocket(io, app.sessionStore, app

Express redirect error: can't set headers after they are sent

ε祈祈猫儿з 提交于 2020-07-18 09:47:27
问题 When this code hits the redirect line it throws the 'Can't set headers after they are sent error' and doesn't redirect. I'm guilty of not fully understanding headers and how express works with them. This link about this error is confusing me a bit, probably because I don't have a basic enough understanding of what's going on. Also, I know this is a bit of a naive approach to authenticating, but I'm just trying to get basic things to work. app.post('/api/login', function(req, res) { if (req

How to mock a middleware in supertest?

﹥>﹥吖頭↗ 提交于 2020-07-18 07:01:49
问题 I want to test if the middleware in app.js is called. Although I mock the module work.js , it still runs the original code. app.js const work = require('./work') const express = require('require') const app = express() .use(work) .use(...) .get(...) module.exports = app work.js function work(req, res, next){...} module.exports = work app-test.js const supertest = require('supertest') const app = require('../app') test('test middleware in app.js', async(done) => { jest.mock('../work', () =>

How do I setup code coverage on my Express based API?

江枫思渺然 提交于 2020-07-18 03:44:49
问题 I've been at this problem for a while and I cannot make the existing solutions work for me. I have a Node.js API written in Express.js. I have been writing tests for the API using Mocha, Chai, and Supertest. These test are mostly integration tests. One test may look like: it('should fail to register a new user without the proper information', function(done) { api.post('/user') .send({}) .expect(400) .expect('Content-Type', /json/) .end(function(err, res) { should.exist(res.body); should.exist

How do I setup code coverage on my Express based API?

折月煮酒 提交于 2020-07-18 03:44:41
问题 I've been at this problem for a while and I cannot make the existing solutions work for me. I have a Node.js API written in Express.js. I have been writing tests for the API using Mocha, Chai, and Supertest. These test are mostly integration tests. One test may look like: it('should fail to register a new user without the proper information', function(done) { api.post('/user') .send({}) .expect(400) .expect('Content-Type', /json/) .end(function(err, res) { should.exist(res.body); should.exist

How do I setup code coverage on my Express based API?

只愿长相守 提交于 2020-07-18 03:44:09
问题 I've been at this problem for a while and I cannot make the existing solutions work for me. I have a Node.js API written in Express.js. I have been writing tests for the API using Mocha, Chai, and Supertest. These test are mostly integration tests. One test may look like: it('should fail to register a new user without the proper information', function(done) { api.post('/user') .send({}) .expect(400) .expect('Content-Type', /json/) .end(function(err, res) { should.exist(res.body); should.exist

errno: 1251, sqlMessage: 'Client does not support authentication protocol requested by server; consider upgrading MySQL client

限于喜欢 提交于 2020-07-17 13:58:39
问题 I'm creating the simple api project in nodejs. For that i have installed mySql workbench with version 8.0.11. I have created config file, dbConnection.js file and in the dbconnection.js file i have written the following code : var mysql = require('mysql'); var path = require('path'); var config = require(path.resolve('./', 'config')) var connection = mysql.createConnection({ host: config.databaseHost, user: config.databaseUser, password: config.databasePassword, database: config

errno: 1251, sqlMessage: 'Client does not support authentication protocol requested by server; consider upgrading MySQL client

这一生的挚爱 提交于 2020-07-17 13:58:11
问题 I'm creating the simple api project in nodejs. For that i have installed mySql workbench with version 8.0.11. I have created config file, dbConnection.js file and in the dbconnection.js file i have written the following code : var mysql = require('mysql'); var path = require('path'); var config = require(path.resolve('./', 'config')) var connection = mysql.createConnection({ host: config.databaseHost, user: config.databaseUser, password: config.databasePassword, database: config