node.js

Can't pass header with token for redirect NodeJS

好久不见. 提交于 2021-02-11 15:49:03
问题 I've got big problem with my login system in NodeJS. I created login site, when i'm logging in. When i check if login and password is correct i make jwt token. Then i would like to pass it into header and redirect to my user page by get method. I searched a lot of sites and I' cant solve this problem. This is what I try to do: const token = jwt.sign({_id: id}, process.env.TOKEN); res.header('auth-token', token); res.redirect('/admin/admin_panel'); I would like to this work like Postman. I set

how to add last login date in application using nodejs and mongodb?

匆匆过客 提交于 2021-02-11 15:36:00
问题 I'm trying to add last login date in my application.But I can't able to achieve it.The current date and last login date are same in my code....please some one help me......enter image description here [ const mongoose = require('mongoose'); const Schema = mongoose.Schema; const schema = new Schema({ username: { type: String, unique: true, required: true }, email:{ type:String, unique:true, required:true }, hash: { type: String, required: true }, defaultAccountId:{ type:Number, required:true }

NodeJs UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

点点圈 提交于 2021-02-11 15:33:10
问题 Hello I am working in a user verification task using a middleware to verify if the user exist or not, this is my code: I have an endpoint defined like this: app.get("/login/", verifyUser, userController.login); This is my middleware verifyUser: function verifyUser(req, res, next) { console.log("Midd 1:", req.query); let userInfo = userController.findUserOne(req, res); console.log("userInfo:" + userInfo); next(); } This is my controller method: exports.findUserOne = function (req, res) {

Disable middleware when redirecting

让人想犯罪 __ 提交于 2021-02-11 15:31:14
问题 I have a isAdmin middleware, and there's a page in my website where I want to disable this isAdmin middleware and let the user go to the page /admin/register, how can I disable the isAdmin middleware in a redirect? return res.redirect('/admin/register'); Midlleware : router.all('/admin/*', isAdmin, (req, res, next) => { res.render('validatePassword', {message: 'Please re-enter your password to get access to ' + req.originalUrl, redirectRoute: req.originalUrl}); // next(); }); router.get('

How to download files from node express server?

只愿长相守 提交于 2021-02-11 15:23:40
问题 I have a file on my server (Node.js + Express). I need to download file from server to computer of user. in React app I call the function which would download file: downloadFileFromServer(file) { // file -- name of file fetch(`${Config.baseUrl}/download-file/${this.props.params.idEvent}/${file}`, { method: 'GET' }) .then((response) => { if (response.status >= 400) { throw new Error('Bad response from server'); } return response; }); } On backend I have this route: app.route('/download-file/

Node.js confusion about buffers, streams, pipe, axios, createWriteStream, and createReadStream

大憨熊 提交于 2021-02-11 15:21:54
问题 I'm trying to download an audio file (about 250KB) from Firebase Storage and send it to IBM Cloud Speech-to-Text, using Firebase Cloud Functions (Node 8). I'm using axios to send the HTTP GET request to the download URL. axios returns a stream so I use fs.createReadStream(response) to stream the file to IBM Cloud Speech-to-Text. I don't get an error message, rather nothing is sent to IBM Cloud Speech-to-Text. exports.IBM_Speech_to_Text = functions.firestore.document('Users/{userID}

How to hide a section in .hbs and .js while taking an ember production build

吃可爱长大的小学妹 提交于 2021-02-11 15:21:01
问题 Our Ember application is developed in 2.8 version and we follow POD structure. We are generating two different builds as below 1) For our dev server : No change in code,just do build 2) For our test server: Delete a section in HBS and also remove a route from router.js then do build And we take build using " npm run-scripts build " which is configured in our package.json as below "scripts": { "build": "ember build", "start": "ember server", "test" : "ember test" }, I would like to know in

What's the best way to authenticate and authorize a web and api solution like MERN Stack?

半城伤御伤魂 提交于 2021-02-11 15:19:16
问题 I'm trying to find the best way to implement authorization. At this time, only thing I need is a simple free account, but later I may include user roles for a "premium" account using a payment system like stripe. I have already started reading and experimenting with Auth0 but then found some other ways I can do it. Passport.js + MongoDB, I've seen some examples and work great but I think it is missing a way to control users, rules etc with a friendly panel (like Auth0) Using Auth0 and setting

How to hide a section in .hbs and .js while taking an ember production build

▼魔方 西西 提交于 2021-02-11 15:16:21
问题 Our Ember application is developed in 2.8 version and we follow POD structure. We are generating two different builds as below 1) For our dev server : No change in code,just do build 2) For our test server: Delete a section in HBS and also remove a route from router.js then do build And we take build using " npm run-scripts build " which is configured in our package.json as below "scripts": { "build": "ember build", "start": "ember server", "test" : "ember test" }, I would like to know in

AWS EBS runs into “504 Gateway Time-out”

早过忘川 提交于 2021-02-11 15:14:16
问题 I'm new to using AWS EBS and ECS, so please bear with me if I ask questions that might be obvious for others. To the issue: I've got a single-container Node/Express application that runs on EBS. The local docker container works as expected. On EBS, I can access one endpoint of the API and get the expected output. For the second endpoint, which runs longer (around 10-15 seconds) I get no response and run after 60 seconds into a time out: "504 Gateway Time-out". I wonder how I would approach