node.js

My node js program is giving me a “TypeError: Cannot read property 'then' of undefined”, when reading a json file

荒凉一梦 提交于 2021-02-11 13:41:31
问题 I'm trying to read frpm a json file folder withing my program and i want to use a GET list endpoint to read through browser or postman, but i'm getting the above TypeError. Here is my code: model.js: const fs = require('fs'); function loadTeams() { return new Promise((resolve, reject) => { fs.readFile('./json/prov-nodes.json', (err, data) => { if (err) reject(err); const teams = JSON.parse(data); console.log(teams); resolve(teams); }); }); } app.use(bodyParser.json()); app.get('/list', (req,

Discord bot sends response twice

蓝咒 提交于 2021-02-11 13:39:19
问题 I'm coding a discord.js bot, and whenever I send a command, it gives a response twice. I've concluded it's because I have too many instances running. I try to delete the instances, but it doesn't delete. Sometimes it says "Some instances could not be deleted", and sometimes it doesn't delete at all. And through Terminal SERVICE VERSION ID VM_STATUS DEBUG_MODE default 20191208t223728 aef-default-20191208t223728-0l57 RUNNING default 20191208t223728 aef-default-20191208t223728-jb53 RUNNING

Gatsby XMLHttpRequest

自闭症网瘾萝莉.ら 提交于 2021-02-11 13:38:24
问题 In short: I want to use XMLHttpRequest in Gatsby, which works in development mode, but fails in production ( gatsby build ) mode, which I can't get fixed. Some more information: I want to access an API (to be precise the GitHub API). Therefore I make an HTTP request like that: const repoRequest = new XMLHttpRequest(); const repoUrl = "https://api.github.com/user/repos?visibility=all?type=all"; repoRequest.open("GET", repoUrl); repoRequest.setRequestHeader("Authorization", "token <here would

Spotify API error 400: “only valid bearer authentication supported”

拈花ヽ惹草 提交于 2021-02-11 13:37:30
问题 I was using the api to try and get the data of my profile through the access token. I used the given code from the authorization example code given in the website, and I used let parsed = queryString.parse(window.location.search); let accessToken = parsed.access_token; console.log(parsed); console.log(accessToken); fetch('https://api.spotify.com/v1/me', { headers: {'Authorization': 'Bearer' + accessToken}, json: true }).then((res) => res.json()) .then(data => console.log(data)); } But the 400

Spotify API error 400: “only valid bearer authentication supported”

旧时模样 提交于 2021-02-11 13:33:06
问题 I was using the api to try and get the data of my profile through the access token. I used the given code from the authorization example code given in the website, and I used let parsed = queryString.parse(window.location.search); let accessToken = parsed.access_token; console.log(parsed); console.log(accessToken); fetch('https://api.spotify.com/v1/me', { headers: {'Authorization': 'Bearer' + accessToken}, json: true }).then((res) => res.json()) .then(data => console.log(data)); } But the 400

How to pass C++11 flag down to “npm install”?

女生的网名这么多〃 提交于 2021-02-11 13:32:55
问题 I am trying to install the "opencv4nodejs" package on a MAC by running this command: CXXFLAGS=-std=gnu++11 npm i -g opencv4nodejs That gives me the following error: /usr/local/lib/node_modules/opencv4nodejs/node_modules/opencv-build/opencv/opencv/modules/highgui/src/window_cocoa.mm:269:25: error: non-constant-expression cannot be narrowed from type 'int' to 'CGFloat' (aka 'double') in initializer list [-Wc++11-narrowing] NSSize size = { width, height }; ^~~~~ /usr/local/lib/node_modules

Display edited/styled text - react

為{幸葍}努か 提交于 2021-02-11 13:32:08
问题 I am building a web app for posting announcements. The user get to use a rich text editor, meaning he can make letters bold, underline them and so one. I am then saving this text with the description "content" in my mongodb database as a string. Every post has a title and a content. When i am displaying the post instead of showing " this text is strong " it is showing "< strong>this text is strong< /strong>". (added a space in < strong> cause it would make it strong otherwise. you get what i

Retrieve Mongoose Query Queue Time Metrics

久未见 提交于 2021-02-11 13:30:10
问题 In order to optimize the connection pool size, I thought it would make sense to graph query queue times. Is it possible to retrieve this metric from Mongoose? 回答1: See here for node monitoring. You need cmap events that apparently aren't documented there, see Ruby docs for example but they should be published by the node driver also. Track ConnectionCheckOutStarted and ConnectionCheckOutSucceeded and subtract the times to get the wait time. 来源: https://stackoverflow.com/questions/63652084

Retrieve Mongoose Query Queue Time Metrics

限于喜欢 提交于 2021-02-11 13:29:05
问题 In order to optimize the connection pool size, I thought it would make sense to graph query queue times. Is it possible to retrieve this metric from Mongoose? 回答1: See here for node monitoring. You need cmap events that apparently aren't documented there, see Ruby docs for example but they should be published by the node driver also. Track ConnectionCheckOutStarted and ConnectionCheckOutSucceeded and subtract the times to get the wait time. 来源: https://stackoverflow.com/questions/63652084

How to set multiple views folder in Express.js app

蹲街弑〆低调 提交于 2021-02-11 13:28:48
问题 When I have one views folder specified it will serve files, but when I specify a second alongside it does not work. I have tried numerous things, to no avail. Here is my code: app.use(express.static('views')); //app.set('views', [__dirname + '/views', __dirname + '/views/views2']); app.use("/views", express.static(__dirname + "/views")); app.use("/views2", express.static(__dirname + "/views2")); The app.set doesn't work at all and so I commented it out here, and the last two lines are not