node.js

passport.js session lost after redirect

这一生的挚爱 提交于 2021-02-19 05:42:08
问题 I am trying to integrate passport into my node.js app. app.js file const app = express(); app.set('view engine', 'pug'); app.use('/libs', express.static('node_modules')); require('../config/auth.config')(app, data, passport); app.use((req, res, next) => { res.locals.user = req.user; next(); }); app.get('/', (req, res) => { // those objects are populated correctly after redirect from auth middleware console.log(req.session) console.log(req.user) return res.render('home'); }); app.get('/login',

Unhandled promise rejection - Error: Can't set headers after they are sent

前提是你 提交于 2021-02-19 05:42:08
问题 I am new to node, and I have a simple situation, where I am posting to an endpoint on a node/express app. The issue is that I get: POST /api/v2/user 500 25.378 ms - 54 (node:19024) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: Can't set headers after they are sent. (node:19024) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit

Setting global variables in a script loaded by jsdom

…衆ロ難τιáo~ 提交于 2021-02-19 05:35:08
问题 I'm trying to run some browser code in Node.js in order to simplify testing (deasync is the reason). Currently, I use jsdom to parse the only html file. At first, I was trying to make it also load the scripts, which are linked in <script> tags. But due to some stupid issues with relative file paths I have switched to passing a list of absolute paths to the script files as a parameter to jsdom.env function. Now I'm pretty sure that jsdom finds my scripts properly, but I cannot set any global

“document is not defined ” error in ejs file which is to be used with res.render() in node.js?

我是研究僧i 提交于 2021-02-19 05:34:18
问题 I have this ejs file which is to be send as a response using res.render() in node.js <!DOCTYPE html> <html> <head> <title>pilcit</title> </head> <body> <% var btn = document.getElementById('btn');%> <% btn.style.background="blue"; %> <div class="pt-5"> <div class="container-fluid"> <h1 style="color:blue;" align=center>Pilcit</h2> <h4 style="color:#369bf4" align="center">The online clipboard</h4> <div> <textarea class="form-control mt-5" name="content" rows="12"> <%= result.content %> <

How to use RxJS, MySQL and NodeJS

北城以北 提交于 2021-02-19 05:34:17
问题 I need a with RxJS for MySQL in NodeJS. Could someone give me an example for one select? On front-end I will use Angular2. 回答1: In my case, I'm using the MySQL npm package in a desktop application made with Electron and Angular. However the same should work even on a plain NodeJS application by installing and importing rxjs. I've first installed mysql and @types/mysql package with: npm install --saved-dev mysql @types/mysql Then I've created a MySQL service: import { Injectable } from '

Can I start a socket.io/websocket server in browser?

徘徊边缘 提交于 2021-02-19 05:34:00
问题 There question about this before, the answer is no. But now, with browserify/webpack, can I just write code like I would on server and it will run in browser, or is there any restriction that would make this impossible? 回答1: No, you cannot. Starting a server in a browser requires access to low level functionality that simply to does not exist in a browser. Browserify cannot add fundamental low-level features to the browser that it does not have that would require additional native code

How to make a delay between two messages in bot framework - Node.js

ぃ、小莉子 提交于 2021-02-19 05:33:23
问题 I am developing a bot that is connected to our client application using Direct Line using botbuilder JS V4. for some reasons, messages are sent with a wrong order to the bot. For example: User: hello Bot: How can I help you? Bot: Hi, I am a robot. As a solution, I added a delay of two seconds between messages in many of my bot's dialogues. What is the right way to do that? And is this the recommended way to fix this issue? Using setTimeout() async greetUser(step) { ... await step.context

Hover on element and getComputedStyle in Node.js using Puppeteer?

我只是一个虾纸丫 提交于 2021-02-19 05:31:38
问题 I want to hover on some element, let say document.getElementById("abc") and find its hover computed style. How should I do it in Node.js using Puppeteer? 回答1: You can use the following solution to iterate and hover over certain elements to obtain the computed style: const elements = await page.$$('.abc'); const data = []; for (let i = 0; i < elements.length; i++) { await elements[i].hover(); data.push(await page.evaluate(element => window.getComputedStyle(element), elements[i])); } console

Hover on element and getComputedStyle in Node.js using Puppeteer?

自作多情 提交于 2021-02-19 05:31:16
问题 I want to hover on some element, let say document.getElementById("abc") and find its hover computed style. How should I do it in Node.js using Puppeteer? 回答1: You can use the following solution to iterate and hover over certain elements to obtain the computed style: const elements = await page.$$('.abc'); const data = []; for (let i = 0; i < elements.length; i++) { await elements[i].hover(); data.push(await page.evaluate(element => window.getComputedStyle(element), elements[i])); } console

How to listen to different UDP ports on the same address within the same process in Node.js

泄露秘密 提交于 2021-02-19 05:27:16
问题 I'm writing a Node.js app to control a small drone. Here are the instructions from the SDK: Use Wi-Fi to establish a connection between the Tello and PC, Mac, or mobile device. Send Command & Receive Response Tello IP: 192.168.10.1 UDP PORT: 8889 <<-->> PC/Mac/Mobile Step 1: Set up a UDP client on the PC, Mac, or mobile device to send and receive message from the Tello via the same port. Step 2: Before sending any other commands, send 'command' to the Tello via UDP PORT 8889 to initiate SDK