express

Retrieving Images stored in Mongodb with Nodejs

雨燕双飞 提交于 2021-02-11 11:59:25
问题 I have small thumbnails stored in a MongoDB collection. While I can extract them with a .findOne() I can not serve them back over an ExpressJS route correctly. I am not storing thumbs on disk as the heroku environment does not guarantee persisted storage. I am not using GridFS as these are thumbs < 16MB. Inserting a a new document into the collection goes something like this: MongoClient.connect(url, function(err, db){ var newImg = fs.readFileSync(req.file.path); var encImg = newImg.toString(

Cannot GET/POST with express Router()

☆樱花仙子☆ 提交于 2021-02-11 11:54:15
问题 So I've been trying to work this out for some time now and I'm missing something here. I'm trying to determine the best practice for setting up routes in Express. I'd like to separate the different routes I have setup by file. I'm trying to use the Express Router module, but I can't get it to work. Here is my main server file: var express = require('express'); var handlebars = require( 'express-handlebars' ); var path = require('path'); var favicon = require('serve-favicon'); var logger =

Retrieving Images stored in Mongodb with Nodejs

十年热恋 提交于 2021-02-11 11:52:45
问题 I have small thumbnails stored in a MongoDB collection. While I can extract them with a .findOne() I can not serve them back over an ExpressJS route correctly. I am not storing thumbs on disk as the heroku environment does not guarantee persisted storage. I am not using GridFS as these are thumbs < 16MB. Inserting a a new document into the collection goes something like this: MongoClient.connect(url, function(err, db){ var newImg = fs.readFileSync(req.file.path); var encImg = newImg.toString(

node/express - missing ) after argument list [closed]

我们两清 提交于 2021-02-11 08:17:07
问题 Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Improve this question new to node... const express = require('express'); const bodyParser= require('body-parser'); const MongoClient = require('mongodb').MongoClient; const app = express(); app.use(bodyParser.urlencoded({extended: true})); app.set('view engine', 'ejs'); module

Send a POST request on the server with Express.js

二次信任 提交于 2021-02-11 07:44:18
问题 I'm running into a small issue with something I thought was possible. I want to have two express routes, one GET route /post-data and one POST route /post-recieve . The code would look something like this: app.get('/post-data', (req, res, next) => { //set url to '/post-recieve' and set body / headers }) app.post('/post-recieve', (req, res, next) => { return res.json(res.body) }) Now, when you visit /post-data you should be instantly redirected to /post-recieve except if you look in the

How to send a post request to mailchimp on express through react

∥☆過路亽.° 提交于 2021-02-11 07:21:55
问题 I am trying to send a new membership from a form in react to my express server to add to the mailchimp memberlist I am getting a cors error and I don't know if I am missing any proxys. I want a user to be able to sign up in react and then it sends it to the mailchimp database I have been able to get the members list but I am not allowed to post to it : This is my express backend : const express = require('express'); const Mailchimp = require('mailchimp-api-v3'); require('dotenv').config();

nodejs express url rewrite?

穿精又带淫゛_ 提交于 2021-02-11 06:55:54
问题 I am new to nodejs and just started learning it. I started with express. Everything's good but have a question not sure if this needs to be URL rewrite or URL redirect. views folder looks like below, (jade files) views - index - news - videos The first page definitely is index, url is localhost:3000. Now I want my news page to be the index page, so when I enter localhost:3000 or localhost:3000/news, I want always to see the news.jade content. but I don't want to duplicate news.jade to index

jwt.verify not throwing error for expired tokens

雨燕双飞 提交于 2021-02-10 23:30:12
问题 I'm using JWT - jsonwebtokens in Nodejs. I'm creating a token and want to throw an error if the token expires. My token is created successfully and I'm checking the token expiry in middleware of Apis in Expressjs. Then token is sent from Angular in headers and the expiration is checked in middleware. This is how I'm creating the token: var token = jwt.sign({ id: id, expiresIn: '2m' }, 'mysecretkey' ); This is how my middlware looks like: var token = req.headers['authorization'] var idToken =

jwt.verify not throwing error for expired tokens

余生长醉 提交于 2021-02-10 23:28:55
问题 I'm using JWT - jsonwebtokens in Nodejs. I'm creating a token and want to throw an error if the token expires. My token is created successfully and I'm checking the token expiry in middleware of Apis in Expressjs. Then token is sent from Angular in headers and the expiration is checked in middleware. This is how I'm creating the token: var token = jwt.sign({ id: id, expiresIn: '2m' }, 'mysecretkey' ); This is how my middlware looks like: var token = req.headers['authorization'] var idToken =

Node.js - PostgreSQL (pg) : Client has already been connected. You cannot reuse a client

左心房为你撑大大i 提交于 2021-02-10 22:17:38
问题 I am just trying to write simple register/login system. I am trying to find if username exists. Here is the steps : Go localhost:3000/users/register page Fill in all fields and click register button Checking my command line if username exists it should print it with console.log Everything works fine until now. When I go back to the register page, I fill in all fields again and click register button. Then it throws it in command line : Error: Client has already been connected. You cannot reuse