express

Mongoose schema option change doesn't reflect in database

陌路散爱 提交于 2021-01-28 06:17:50
问题 I have a mongoose schema defined like the following one: { Username: { type: String, unique: true, required: true, }, Password: { type: String, required: true, minlength: 10, maxlength: 20 } } For example after we launch the production build of our app which is running live, if I want to change "unique" to unique: false for the "Username" how should I do it? So on my machine when the server is running i created a User with Username and Password, mongo created User for me, now i changed the

Multiple redirects to the swagger endpoint using swagger in express app with serverless

与世无争的帅哥 提交于 2021-01-28 06:10:54
问题 I'm making an application with express-serverless and I want to use swagger-jsdoc and swagger-ui-express during offline development. This is my configuration for swagger: const express = require('serverless-express/express'); const router = express.Router(); const options = { swaggerDefinition: { info: { title: 'REST - Swagger', version: '1.0.0', description: 'REST API with Swagger doc', contact: { email: 'me@someemail.com' } }, tags: [ { name: 'Stuff', description: 'Stuff API' } ], schemes:

Trying to parse JSON Object from POST Request in Express v4 using body-parser

别来无恙 提交于 2021-01-28 05:29:33
问题 I'm currently teaching myself more about server code, specifically using Node.js and Express, and I'm having a lot of trouble with receiving and parsing a JSON object sent from a POST request. I have looked at numerous other posts (linked to below) and I can't figure out for the life of me what's going wrong. Here's what I've looked at: Javascript: Send JSON Object with AJAX Javascript : Send JSON Object with Ajax? How do I consume the JSON POST data in an Express application How do I consume

How to get a multiple result in mongoose and combine it in one single response

我只是一个虾纸丫 提交于 2021-01-28 05:21:13
问题 In a API(Route) call, I wish to have 3 mongoose query and then combine results to form a response json. Query student .countDocuments ( {} ) .then(stundentNumber => { return stundentNumber }) teacher .countDocuments ( {} ) .then(teacherNumber => { return teacherNumber; }) staff .countDocuments ( {} ) .then(staffNumber => { return staffNumber; }); Desired Response res.json({ teacher: teacherNumber, student: stundentNumber, staff: staffNumber }); How can it be done using nodejs/mongoose 回答1: If

Poll and get MQTT messages from AJAX in browser

最后都变了- 提交于 2021-01-28 05:06:09
问题 Beginner here. Ok, I'm trying to accomplish a simple data flow: MQTT-Data-source ---> MQTT Broker ---> NodeJS-MQTT-Client ---> AJAX-on-web-browser (polling-every-3-seconds) I want to be able to get the MQTT message and show it in the AJAX component in browser side. Secondly, on console.log(mqttMessage); , how do i clear previous messages? Because on console I can see all previous data as well as the new data adding up. I'm using mqtt.js for my nodejs mqtt support on Express. //Server.js var

await is only valid in async function error for a async function [duplicate]

喜夏-厌秋 提交于 2021-01-28 05:03:29
问题 This question already has answers here : await is only valid in async function (9 answers) Closed 8 months ago . I am fetching 2 URLs at the same time using Promise all but when I am calling this function using await (as getAllURLs is async function) it gives me an error, How can I solve this problem? const fetch = require("node-fetch"); let urls = ["https://jsonplaceholder.typicode.com/users","https://jsonplaceholder.typicode.com/users"] async function getAllUrls(urls) { try { var data =

How can I get my Express app to respect the Orientation EXIF data on upload?

只谈情不闲聊 提交于 2021-01-28 05:02:26
问题 I have an Express application that uses multer to upload images to an S3 bucket. I'm not doing anything special, just a straight upload, but when they are displayed in the browser some of the iPhone images are sideways. I know this is technically a browser bug and Firefox now supports the image-orientation rule, but Chrome still displays the images on their side. Is there a way I can have Express read the EXIF data and just rotate them before uploading? 回答1: Right, I figured it out. I used a

passport-local-mongoose Error message change

无人久伴 提交于 2021-01-28 04:34:03
问题 I want to change my Error Messages with the passport local mongoose middleware. but it didn't work: var mongoose = require('mongoose'); var Schema = mongoose.Schema; var passportLocalMongoose = require('passport-local-mongoose'); var Account = new Schema({ username: String, email: String }); Account.plugin(passportLocalMongoose,{ IncorrectUsernameError: 'sdfsd', IncorrectPasswordError: 'sdfsd' }); var User = mongoose.model('Account', Account); module.exports = User; thats my Account.js and

checkbox array returns the last checked value in nodejs, not whole array

大城市里の小女人 提交于 2021-01-28 04:09:58
问题 I am trying to take through req.body the checked values from checkbox. If i check only one there is no problem and on req.body there is an object with the value. If i check more than one then it returns the last one in a row i check. I am using express ejs and express.json() as a body parser. This is a section from my app file where i config the express.json() const express = require("express"); const path = require("path"); const rateLimit = require("express-rate-limit"); const helmet =

Can we serve static files in a node module for a server?

北城余情 提交于 2021-01-28 03:19:40
问题 I'm a begginer so sorry if the question seems stupid but I'm developping a NodeJs server and I'm currently using this (in backend/server.js) to have my public files : app.use(express.static(Path.join(__dirname, '..', 'public'))); But I would like to know if I can add a package of a node module in my paths like : app.use(express.static(Path.join(__dirname, '..', 'node_modules/fuelsdk-node'))); My directory is set like this : How should I import my node module ? Can I use both at the same time