node.js

How to use await with promisify for crypto.randomBytes?

匆匆过客 提交于 2021-02-11 17:01:06
问题 I'm writing a function to generate a random key using crypto.randomBytes, which takes a callback. I'd prefer to use async await so I'm trying to use util.promisify to wraprandom bytes like this: const crypto = require('crypto'); const util = require('util'); const randBytes = util.promisify(crypto.randomBytes); async function genRandKey() { bytes = await randBytes(48).catch((err) => { console.log(err); }); return bytes.toString('hex'); } let result = genRandKey(); console.log('key: ', result)

Proxying file upload with node/express.js and node request results in corrupt files with almost dobble the file size

馋奶兔 提交于 2021-02-11 17:00:42
问题 I'm trying to proxy our main server via a node.js/express.js server. I've got everything working as it should except file uploads. Files are uploaded and reach the server, however somewhere between the data being passed over to node.js request and the data reaching the server the file is corrupted. A file with content-length 1833 ends up having a content-length 3274 once it reaches the server. I expect the file that reaches the server to stay at 1833. Running without the proxy works as

host public node js website on amazon AWS LightSail without Bitnami

非 Y 不嫁゛ 提交于 2021-02-11 17:00:28
问题 I have an amazon AWS LightSail instance and have installed Node js downloaded from nodejs.org. Now the setup is complete and I am able to launch my nodejs webpage inside LightSail instance using "http://localhost but when I try to do it using the lightsail public IP from any other laptop, it not getting accessible (getting web error as "This site can’t be reached"). I have set the node js to listen to port 80 which is open by default. A lot of materials shows that bitnami as a way to do it

Error: Failed to lookup view “index” in views directory “./views”

妖精的绣舞 提交于 2021-02-11 16:49:11
问题 This question has been asked before, but I can't still figure out what I'm doing wrong. It al works fine on my localhost, but as soon as I deploy it it will give me this error. Error: Failed to lookup view "index" in views directory "./views" I've tried different methods like: app.set('views', './views'); and app.set('views', 'views'); Does anyone have some advice on what to try next? This is my folder structure: These are my dependencies: "body-parser": "^1.19.0", "ejs": "^3.0.1", "express":

Azure AD B2C (NodeJS): Unauthorized 401 error for a request with a valid token

我的梦境 提交于 2021-02-11 16:48:57
问题 I'm using Azure AD B2C for authentication for my NodeJS API. However, I keep receiving a 401 Unauthorized error by Azure AD B2C. When I add ignoreExpiration: true to my AAD auth options, I do not get a 401 Unauthorized error and my API works fine. However, once I remove the ignoreExpiration, I get the 401 Unauthorized error. I even generated a new token, verified that it is valid (and not expired) by decoding the token using https://jwt.io/. I even made sure it has the correct scope. The API

Minecraft Server Client via Discord Bot

南楼画角 提交于 2021-02-11 16:44:41
问题 Currently I am trying to set up a discord bot that would log me into a server, and convey the messages sent by players into a discord channel. I am not an admin nor have any staff related things on the server, so i'm unable to ftp in and use rcon , I want it to log my user in, and just convey messages back and forth. Is this possible? So, I have so far tried via npm packages , but none of them seem to do what i want. I am trying to host a node.js discord.js bot on my home computer that is

Minecraft Server Client via Discord Bot

試著忘記壹切 提交于 2021-02-11 16:43:53
问题 Currently I am trying to set up a discord bot that would log me into a server, and convey the messages sent by players into a discord channel. I am not an admin nor have any staff related things on the server, so i'm unable to ftp in and use rcon , I want it to log my user in, and just convey messages back and forth. Is this possible? So, I have so far tried via npm packages , but none of them seem to do what i want. I am trying to host a node.js discord.js bot on my home computer that is

How to go about adding asynchronous information to a global array?

狂风中的少年 提交于 2021-02-11 16:42:41
问题 I'm learning Node JS as well as how to access an API's information, and I've come across a problem where when I push values to an array, the info never gets added globally. So let's say I have var albIds= new Array(5) , the values never get added. Through looking at this and this I now know that the issue is that the information never gets into the array by the time I call it, due to the synchronous code being done first, however, I am confused at how to make the synchronous wait for the

Node.js, socket-io based one to one chat engine working fine on LOCAL but not working when running on different laptops using ngrok

回眸只為那壹抹淺笑 提交于 2021-02-11 16:39:29
问题 I am working on a chat server and it's working fine on local but whenever I try to run the project using ngrok then me and my friend are unable to chat. var socket = io('http://localhost:7777', { query: { username: '<%= user %>' } }); Can anyone guide me how to make this public? Because the IP address changes everytime when connected to internet. and var app = express(); const chatServer = require('http').createServer(app); chatServer.listen(7777); I'm working in node.js for the first time

Why is passport.deserializeUser called after req.user has been restored?

橙三吉。 提交于 2021-02-11 16:38:44
问题 According to the Passport Documentation on Sessions ...only the user ID is serialized to the session, keeping the amount of data stored within the session small. When subsequent requests are received, this ID is used to find the user, which will be restored to req.user. However my test SPA which is based on Passport form-based authentication sample with debug messages added indicates req.user has already been restored before the app.get route handler is triggered. Here is the output from an