node.js

How to call Prometheus Histogram.observe() on serveral Functions at once in NodeJS

不羁的心 提交于 2021-02-11 15:12:16
问题 I am monitoring a NodeJS app using Prometheus. Creating a Histogram like this const histogram = new client.Histogram({ name: 'node_request_duration_seconds', help: 'Histogram for the duration in seconds.', buckets: [1, 2, 5, 6, 10] }); Now I am calling histogram.observe() like this to monitor a request to the path '/' const app = express(); app.get('/', (req, res) => { //Simulate a sleep var start = new Date() var simulateTime = 1000 setTimeout(function(argument) { // execution time simulated

How to attach an image to an embed

自作多情 提交于 2021-02-11 15:08:34
问题 I've been trying to figure this out for a while. I can't figure out how to make a bot attach an image to an embed. I'm trying to upload a picture from my PC. const commando = require('discord.js-commando'); const discord = require('discord.js') class HoundCommand extends commando.Command { constructor(client) { super(client, { name: 'hound', group: 'simple', memberName: 'hound', description: 'Tells info about hound' }); } async run(message, args) { var myInfo = new discord.RichEmbed()

Conditional GET ignored with fetch API

喜你入骨 提交于 2021-02-11 15:06:32
问题 I am fetching and parsing an RSS feed (https://www.mangaupdates.com/rss.php) with Discord.js/Node.js. I'm currently trying to add a conditional If-Modified-Since header to make a conditional GET request to the RSS feed. Here is my code: fetch(mangaUpdatesRSS, { method: 'GET', headers: {'If-Modified-Since': new Date().toUTCString()} }) .then(res => { console.log(res.status); The response status is always 200 even though it should only be making a request if it's been modified since the time of

Mongo Call does not remove parameters

守給你的承諾、 提交于 2021-02-11 15:06:25
问题 Im using node with mongo, and I want for the mongo get call to stop returning some values, such as _id and uid. Everything that ive read says that this call should work, but when I print the json value on my UI, it still has those values. app.get('/users', async function(req, res){ console.log("Getting User Info!"); await client.connect(); const db = client.db('database'); var uidparam = req.header("uid"); db.collection("users").findOne({"uid": uidparam}, { _id: 0, uid: 0, }, function(err,

Mongo Call does not remove parameters

假如想象 提交于 2021-02-11 15:04:22
问题 Im using node with mongo, and I want for the mongo get call to stop returning some values, such as _id and uid. Everything that ive read says that this call should work, but when I print the json value on my UI, it still has those values. app.get('/users', async function(req, res){ console.log("Getting User Info!"); await client.connect(); const db = client.db('database'); var uidparam = req.header("uid"); db.collection("users").findOne({"uid": uidparam}, { _id: 0, uid: 0, }, function(err,

My $push method in Mongoose does not work ok

孤街醉人 提交于 2021-02-11 15:02:26
问题 I have a problem understanding why $push creates only one element in nested array and shows only the id of that element const mongoose = require('mongoose'); let historySchema = new mongoose.Schema({ time: { type:String } }) //users schema let userSchema = new mongoose.Schema({ name:{ type:String, }, dob:{ type:String, }, email:{ type:String, }, noOfpeopleClimbing:{ type: Number, default:0 }, details:{ type:String, }, status:{ type: Boolean, default: false }, timeIn:{ type: Number, default: 0

How to add a role with an ID that is saved in an JSON file discord.js v12?

我怕爱的太早我们不能终老 提交于 2021-02-11 15:00:19
问题 I'm making a warn command and I've run into a problem with the role giving. First, I have a command that sets the warned role for the guild. It reacts to &setwarnedrole {role ID}. It saves the role ID into a JSON file, next to the guild ID. Then, the warn command reads the file, and gets the role ID that was stored with the guild ID the command is executed in. You use &warn {user ping/user ID} to warn people. But when I do that, it gives me an error: TypeError [INVALID_TYPE]: Supplied roles

Node.JS Firebase Auth - Is there a way to keep a user session like with client side Firebase Auth?

[亡魂溺海] 提交于 2021-02-11 14:59:52
问题 I am learning Node.JS and I am trying to bring Firebase Auth into my application. With client-side firebase auth, you can just do firebase.auth().currentUser but in node, as the script is not run on the client, but once on the server, you cannot use firebase.auth().currentUser . Is there a way involving sessions or cookies (I think) to get user data and use normal Firebase Auth operations from node just like client side Firebase Auth? (I am using express with Node) 回答1: As you've found there

Node.js Javascript don't download images from array

对着背影说爱祢 提交于 2021-02-11 14:57:35
问题 I'm implementing a image downloader because I want display them from client and not from URLs, inside a class I have a method that takes URLs from a datafile and then download them in samefolder. messaggi[] array is a result of reading datafile and I simplify in this snippet declaring it (of course in my code isn't declared as you see but it absolutly works as this result). the problem is that in this snippet doesn't arrive to download images and sometimes just download 1 of them and is

How to see the files that were written to disk from node.js app hosted on heroku?

与世无争的帅哥 提交于 2021-02-11 14:57:26
问题 I have a node.js app on heroku and I sometimes need to write files to heroku. Do you know how to see those files? Should I delete them after I am finished using them? I do not want to use memory for no reason. 回答1: Heroku (and other container based platforms) are different from traditional servers that you might be used to. It's worth bearing in mind that the Heroku filesystem is ephemeral - that means that any changes to the filesystem whilst the dyno is running only last until that dyno is