express

Atlas MongoDB connection

て烟熏妆下的殇ゞ 提交于 2020-06-16 17:10:51
问题 I am trying to connect to Atlas MongoDB with the following URI (provided by mongodb connection string ) module.exports = { mongoURI:'mongodb+srv://<user>:<password>@cluster0-un6sk.mongodb.net/test? retryWrites=true' }; //connect to mongoose mongoose .connect(db) .then( ()=>console.log('mongoDB connected')) .catch(err => console.log(err)); I get the following error : { MongoNetworkError: connection 3 to cluster0-shard-00-00-un6sk.mongodb.net:27017 closed at TLSSocket.<anonymous> (C:\Users

Express send base-64 encoded png-image

别来无恙 提交于 2020-06-16 11:41:33
问题 In my node.js app I`m trying to respond with an image. This image was saved before postgresql as text. The text looks just like this: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAAE But when I try to return it as an image: res.type('image/png'); res.send(image_string); Or binary: res.send(image_string,'binary'); It shows a empty image-element: What do I wrong? Thanks 回答1: I solved it by using a buffer: const im = image_string.split(",")[1]; const img = Buffer.from(im, 'base64'); res

Express send base-64 encoded png-image

早过忘川 提交于 2020-06-16 11:38:02
问题 In my node.js app I`m trying to respond with an image. This image was saved before postgresql as text. The text looks just like this: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAAE But when I try to return it as an image: res.type('image/png'); res.send(image_string); Or binary: res.send(image_string,'binary'); It shows a empty image-element: What do I wrong? Thanks 回答1: I solved it by using a buffer: const im = image_string.split(",")[1]; const img = Buffer.from(im, 'base64'); res

Using await / async with mocha, chai

非 Y 不嫁゛ 提交于 2020-06-16 02:25:30
问题 I'm quite new to node and express. And have been trying to write test code using mocha, chai and chai-http. Here's the part of source code. const mongoose = require('mongoose'), User = require('../../models/user'); const mongoUrl = 'mongodb://xxxxxxxxxxx'; describe('/test', function() { before('connect', function() { return mongoose.createConnection(mongoUrl); }); beforeEach(async function(done) { try { await User.remove({}); // <-- This doesn't work chai.request('http://localhost:3000')

On Safari, cookies are not saved when sent with redirect

前提是你 提交于 2020-06-15 11:24:58
问题 I have implemented an OAuth2 client, in which the first step is to send a user to the relevant 3rd party (facebook for this example), I set them a state cookie, and when they return from facebook I validate that state cookie. In Chrome, everything is great. When I send the user to the redirect URL, I can see (using inspect element) that they have the state cookie I set. However, when I try on (desktop) safari on latest MacOS, I don't see that cookie. I set the cookie in the response for my

Create file based on buffer data in nodejs

我的梦境 提交于 2020-06-15 04:09:16
问题 I am sending from front end client side a file, on the server side I have something like this: { name: 'CV-FILIPECOSTA.pdf', data: <Buffer 25 50 44 46 2d 31 2e 35 0d 25 e2 e3 cf d3 0d 0a 31 20 30 20 6f 62 6a 0d 3c 3c 2f 4d 65 74 61 64 61 74 61 20 32 20 30 20 52 2f 4f 43 50 72 6f 70 65 72 ... >, encoding: '7bit', mimetype: 'application/pdf', mv: [Function: mv] } What I need is to create the file may be based on that buffer that is there, how can I do it? I already searched a lot and didn't

Create file based on buffer data in nodejs

╄→гoц情女王★ 提交于 2020-06-15 04:03:58
问题 I am sending from front end client side a file, on the server side I have something like this: { name: 'CV-FILIPECOSTA.pdf', data: <Buffer 25 50 44 46 2d 31 2e 35 0d 25 e2 e3 cf d3 0d 0a 31 20 30 20 6f 62 6a 0d 3c 3c 2f 4d 65 74 61 64 61 74 61 20 32 20 30 20 52 2f 4f 43 50 72 6f 70 65 72 ... >, encoding: '7bit', mimetype: 'application/pdf', mv: [Function: mv] } What I need is to create the file may be based on that buffer that is there, how can I do it? I already searched a lot and didn't

Create file based on buffer data in nodejs

北慕城南 提交于 2020-06-15 04:03:53
问题 I am sending from front end client side a file, on the server side I have something like this: { name: 'CV-FILIPECOSTA.pdf', data: <Buffer 25 50 44 46 2d 31 2e 35 0d 25 e2 e3 cf d3 0d 0a 31 20 30 20 6f 62 6a 0d 3c 3c 2f 4d 65 74 61 64 61 74 61 20 32 20 30 20 52 2f 4f 43 50 72 6f 70 65 72 ... >, encoding: '7bit', mimetype: 'application/pdf', mv: [Function: mv] } What I need is to create the file may be based on that buffer that is there, how can I do it? I already searched a lot and didn't

How to use query parameters in Nest.js?

跟風遠走 提交于 2020-06-14 04:17:04
问题 I am a freshman in Nest.js. And my code as below @Get('findByFilter/:params') async findByFilter(@Query() query): Promise<Article[]> { } I have used postman to test this router http://localhost:3000/article/findByFilter/bug?google=1&baidu=2 Actually, I can get the query result { google: '1', baidu: '2' } . But I'm not clear why the url has a string 'bug' ? If I delete that word just like http://localhost:3000/article/findByFilter?google=1&baidu=2 then the postman will shows statusCode 404 .

How to use query parameters in Nest.js?

会有一股神秘感。 提交于 2020-06-14 04:16:29
问题 I am a freshman in Nest.js. And my code as below @Get('findByFilter/:params') async findByFilter(@Query() query): Promise<Article[]> { } I have used postman to test this router http://localhost:3000/article/findByFilter/bug?google=1&baidu=2 Actually, I can get the query result { google: '1', baidu: '2' } . But I'm not clear why the url has a string 'bug' ? If I delete that word just like http://localhost:3000/article/findByFilter?google=1&baidu=2 then the postman will shows statusCode 404 .