express

How to convert JPG image to WEBP format in Node js ?

二次信任 提交于 2020-06-26 06:53:36
问题 I m trying to upload an image using reactJs and save that image in nodeJs using multer middleware.This is working perfectly but now I want to convert that image to webP format using webp-converter which is a small node.js library for converting other image format to webp format and vice- versa. But I m getting this error : Error: Command failed: E:\Zegal\node_modules\webp-converte ib/libwebp_win64/bin/cwebp.exe -q 80 2a3279b820cc23939eea0295228423ee-- inspironal-quote-about-life-inspiring

“Topology was destroyed” when using MongoDB with native driver and Express.js

别说谁变了你拦得住时间么 提交于 2020-06-26 04:03:08
问题 I have implemented simple application that fetches data from MongoDB const express = require('express') const app = express() const port = 3000 const MongoClient = require('mongodb').MongoClient; const assert = require('assert'); const dbConnectionURL = 'mongodb://localhost:27017'; const dbName = 'todo'; const dbClient = new MongoClient(dbConnectionURL); function findTodos(db, callback) { const collection = db.collection('todos'); collection.find({}).toArray(function (err, todos) { assert

How to get path variable in express(node.js)

旧街凉风 提交于 2020-06-25 11:30:12
问题 I am trying to get value of path variable "userId" using req.params but i am getting undefined , if any one can guide me in this problem i ll be very thankful to him. i have place my code below. i have go through some example but those examples are also doing in this way i don't know what is going wrong with my code. thank you, parent router for controller app.use("/user/:userId/group",groupController); Action In Controller Router.post("/", function (req, res, next) { var group = new Group

How do I upload files to a graphql backend implemented using graphql-upload using axios?

戏子无情 提交于 2020-06-25 05:30:26
问题 I have a GraphQL backend implemented using express, express-graphql, graphql and graphql-upload. My GraphQL schema declaration is as follows: type OProject { _id: ID! title: String! theme: String! budget: Float! documentation: String! date: Date } input IProject { title: String! theme: String! budget: Float! file: Upload! } type Mutations { create(data: IProject): OProject } type Mutation { Project: Mutations } I want to make a create request to my GraphQL API at /graphql using axios. How go

How to add Typescript definitions to Express req & res

拜拜、爱过 提交于 2020-06-24 22:29:01
问题 I have a set of controller functions for my REST API and I'm getting lots of the following error TS7006: Parameter 'req' implicitly has an 'any' type. Likewise for res . I've been playing around with typeings etc. but with no success. For example the Request type parameter below does NOT work. Here is an example of the controller files. The reference path is correct. /// <reference path="../../../typings/tsd.d.ts" /> /* globals require */ "use strict"; exports.test = (req : Request, res) => {

what is the most reasonable way apply webpack to a full-stack node app?

早过忘川 提交于 2020-06-24 03:58:27
问题 i've been studying up on webpack for a couple of weeks now, and i've seen many examples of front end setups, and probably just this one setup for a backend. i'm trying to setup a react app with a node back-end (e.g. express, koa, hapi, etc) where i would need at least one transpilation step for the back-end (e.g. babel, coffeescript, etc), and i think it would be nice to use webpack there for consistency vs adding another build mechanism to the mix (e.g. gulp, grunt, etc). it would also be

Pass variable to html template in nodemailer

点点圈 提交于 2020-06-24 03:08:09
问题 I want to send email with nodemailer using html template. In that template I need to inject some dynamically some variables and I really can't do that. My code: var nodemailer = require('nodemailer'); var smtpTransport = require('nodemailer-smtp-transport'); smtpTransport = nodemailer.createTransport(smtpTransport({ host: mailConfig.host, secure: mailConfig.secure, port: mailConfig.port, auth: { user: mailConfig.auth.user, pass: mailConfig.auth.pass } })); var mailOptions = { from: 'my@email

ExpressJS: run a function every 24 hours

自作多情 提交于 2020-06-23 20:22:25
问题 What's the easiest way to run an automated function every 24 hours in ExpressJS? I have searched everywhere for a solution aside from running an infinite loop. Is this in principle the only way to do it? 回答1: you need to use node-cron npm var cron = require('node-cron'); cron.schedule('0 0 * * *', () => { console.log('running a task every day'); }); get other cron formula :https://crontab.guru/examples.html 回答2: In Javascript, you use setTimeout() and setInterval() to schedule something to

ExpressJS: run a function every 24 hours

巧了我就是萌 提交于 2020-06-23 20:22:09
问题 What's the easiest way to run an automated function every 24 hours in ExpressJS? I have searched everywhere for a solution aside from running an infinite loop. Is this in principle the only way to do it? 回答1: you need to use node-cron npm var cron = require('node-cron'); cron.schedule('0 0 * * *', () => { console.log('running a task every day'); }); get other cron formula :https://crontab.guru/examples.html 回答2: In Javascript, you use setTimeout() and setInterval() to schedule something to

How to throw a 404 error in express.js?

霸气de小男生 提交于 2020-06-22 16:40:28
问题 In app.js, I have // catch 404 and forward to error handler app.use(function(req, res, next) { var err = new Error('Not Found'); err.status = 404; next(err); }); so if I request some not exist url like http://localhost/notfound , above code will execute. In exist url like http://localhost/posts/:postId , I would like to throw 404 error when access some not exist postId or deleted postId. Posts.findOne({_id: req.params.id, deleted: false}).exec() .then(function(post) { if(!post) { // How to