express

How to validate dynamic field data on the react client-side and node server-side?

亡梦爱人 提交于 2021-01-29 15:24:00
问题 I have created dynamic input field in the React component, but don't know how to validate this dynamic field data on the client-side when onChange and onSubmit event occurred. I usually use joi or yup to validate data, but don't know how I can validate dynamic field data. Here is my code: import React, { useState } from 'react'; import { v4 as uuidV4 } from 'uuid'; import './styles.css'; const createFieldsObject = (fields) => ({ id: uuidV4(), fields, }); const DynamicTable = ({ fields }) => {

NodeJs api with mongoose any request go to another collection efficient

主宰稳场 提交于 2021-01-29 15:15:20
问题 I'm write nodeJs api for app with users and I want for each user to use another mongo collection. I recognize each user with the URL address in the params fields. everything is work fine. But when I go to collection dynamically it's very slow. any one idea how to do this faster? thanks in advance ;) app.js this code do req in 2.5 seconds POST /login 200 2487.531 ms - 206 app.use("/:businessUrl", (req, res, next) => { console.log(req.params.businessUrl); mongoose .connect(process.env.MONGO_URI

Node Express app.js giving a 404 error for GET request

限于喜欢 提交于 2021-01-29 14:59:31
问题 I have looked at similar questions and they don't seem to answer my problem. I am getting a 404 error when I send a GET request. I have my router in a separate file and then calling my requests in my app.js. I've tried to make my issue as simple as possible for this. Here's what I have: movie-server.js: const express = require('express') const movieRouter = express.Router(); movieRouter .route('/movies') .get((req, res) => { res.send('hello from movies') }) module.exports = movieRouter; app

My express.js and passport.js middleware are all working and are being called, but the page does not redirect

风流意气都作罢 提交于 2021-01-29 14:26:19
问题 I am currently developing a node/express server, and I decided to use passport-local for user authentication along with a local MongoDB server. I am using a POST method from an html form to send the two items, an email and a password (I changed the usernameField item in my instance of LocalStrategy). Using console.log's, I've seen all of the correct and expected behavior from Mongo and Passport. However, the page never redirects with successRedirect or failureRedirect. It looks like the html

How do you get multiple pieces of information out of a collection on a server?

旧城冷巷雨未停 提交于 2021-01-29 14:02:15
问题 Here is a bit of the code I have server.get("/get", getCallback); function getCallback(req,res) { collection.find({}).next(findCallback); function findCallback(err,foundRecord) { if (err == null) { console.log('FOUND: ' + foundRecord); return res.status(200).send(foundRecord); } else throw err; } } It give's me back {"readyState":1} in the console. No matter what I try it's giving me different types of errors. I have no problem-saving data to the collection but as soon as I go to take it out

how to save byte array as zip in angular

丶灬走出姿态 提交于 2021-01-29 14:00:56
问题 I'm trying to download (using FileSaver.saveAs) a byte array getting from the server (nodejs\express) as a zip. I'm manage to download it as zip, but it doesn't open (it is invalid). I had few miss-clarities regarding the way the data should be defined - content type, responseType both in the server and in the client, should I convert it to a blob, etc) - but I think I over-come them with the detailed below code. The problem is at the final function, in the exportAsZip function - the data

Express routing and jsonwebtoken, staying logged in after token creation

喜你入骨 提交于 2021-01-29 13:33:42
问题 I'm having a hard time connecting the last dots building a role based access control api in Express. Following this tutorial and implementing onto my existing program, but I think I am missing the last step and after countless tutorials analysis paralysis has set in. I have since scaled back all my necessary code to what I think is the bare minimum. Currently I am able to create a new user and save them to the mongoose database. I can see the hash by bcrypt is doing its thing and I can see

Node js form submit TypeError: Cannot set property 'userId' of undefined

淺唱寂寞╮ 提交于 2021-01-29 13:09:46
问题 I have added login and registration features to a page in my application in views/employee/login.hbs. When I enter in registration details (email, username, password and conf password), I hit the register button to hopefully be redirected to the views/employee/home.hbs page. However, when I complete this action my MongoDB Compass Community database receives the registration details that I have entered successfully but my browser states 'The site cannot be reached' and URL is "localhost:3000

How to add child row in related table?? (Sequelzie N:M Relationship)

二次信任 提交于 2021-01-29 11:15:42
问题 In my program, I'd like to create a new post named Column contains of many categoris. Also, a category can contain of many posts.(N:M) So I tried to add a category to the post, but it failed. Here is the code I've tried: However, no errors are output to the log. for(var i in column_categorys) { const category = await Category.findOrCreate({ where : { category_name: column_categorys[i], } }) .then(resolve => { return resolve; }) .catch(function(error) { isFail = true; return null; }); await

Service Worker vs Web Worker

戏子无情 提交于 2021-01-29 10:44:41
问题 I wanna implement push notification for my website: Consider we have a shopping site, whenever a user click on one product, the server should push notification to the owner of the product that user (for example John) wants to buy your shoe. (real-time). I have read some articles about web worker (like socket.io) and service workers, I conclude that service workers are the best choice. Am I true? How can I implement that push notification? 回答1: A Service Worker is a special kind of Web Workers