node.js

how to return response to REST api in node js

狂风中的少年 提交于 2021-02-17 05:42:31
问题 I'm new to Node JS. My node js REST api route code is: 'use strict'; module.exports = function(app) { var sequel = require('../controllers/sampleController'); app.get('/task?:email', function(req, res){ res.send(sequel.listByEmail(req.query.email)); }); }; And my listByEmail function is: 'use strict'; var apiKey = '1xxxxxxxxL'; exports.listByEmail = function(emailid) { console.log(emailid); if(emailid != null && emailid != undefined) { var xyz = require("xyz-api")(apiKey); xyz.person

How do you get JSON data using $.getJSON with Node.js

天大地大妈咪最大 提交于 2021-02-17 05:39:28
问题 I'm new to Node.js. I already have a frontend javascript script that uses an API and gets weather data like so: function getTextWeatherUsingStation(theStation){ theURL = 'https://api.weather.gov/stations/' + theStation + '/observations/current'; // return new Promise((resolve, reject) => { $.getJSON(theURL,function(data){ var myJSON = JSON.stringify(data) I read that you can't just use a library as is. I converted it over to a Node.js friendly file by wrapping it in module.exports = { and

Getting Timeout error while connecting MongoDB Atlas with Mongoose

不羁岁月 提交于 2021-02-17 05:38:42
问题 I am trying to connect to my database on MongoDB Atlas using mongoose. But every time it's giving me the following error: (node:2327) UnhandledPromiseRejectionWarning: Error: queryTxt ETIMEOUT cluster0-abjwg.gcp.mongodb.net at QueryReqWrap.onresolve [as oncomplete] (dns.js:206:19) (node:2327) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled

Firestore delete vs update time and performance

妖精的绣舞 提交于 2021-02-17 05:38:07
问题 I have coded a match making system and this system works like that --> when a create operation came to firestore it matches with an older record and the cloud function deletes both of them. But i wonder that when 2 new records are created, is there any chance for matching these 2 with the same old record because the deletion process takes some time? Also, if i do that process with update, is it faster than delete? EDIT: Here is my matchMaker Cloud Function: exports.matchMaker = functions

“await is only valid in async function” discord.js

為{幸葍}努か 提交于 2021-02-17 05:28:13
问题 I'm writing this code and I'm getting a "await is only valid in async function" on the line with an arrow below. I've done a bit of searching around but I'm not entirely sure what's wrong. if (message.attachments.first()) { console.log("cool file.") if (verifyFile(message.attachments.first())) { console.log("epic file!!") ---> await request.get(message.attachments.first().url).then(async (data) => { fs.writeFileSync(`${directory}/${message.author.id}_unobfuscated.lua`, data) var options = {

How to get user's IP address in a bot with node.js?

主宰稳场 提交于 2021-02-17 05:28:08
问题 I am writing a bot in node.js. May I know how can I insert code to console.log the IP address of message sender please? I need the IP address to perform some auto-log in. Many Thanks!! 回答1: You can get ip address from request object by request.connection.remoteAddress 回答2: To get the Ip address of your User var app = require('express')(); app.get("/ip", (req, res) => { console.log(req.ip) // "::ffff:127.0.0.1" ::ffff: is a subnet prefix for IPv4 (32 bit) let ip = req.ip.split(':'); console

How to get user's IP address in a bot with node.js?

女生的网名这么多〃 提交于 2021-02-17 05:27:43
问题 I am writing a bot in node.js. May I know how can I insert code to console.log the IP address of message sender please? I need the IP address to perform some auto-log in. Many Thanks!! 回答1: You can get ip address from request object by request.connection.remoteAddress 回答2: To get the Ip address of your User var app = require('express')(); app.get("/ip", (req, res) => { console.log(req.ip) // "::ffff:127.0.0.1" ::ffff: is a subnet prefix for IPv4 (32 bit) let ip = req.ip.split(':'); console

NodeJS Child Process EXEC Command Failed with NVM Permission denied OSX

天涯浪子 提交于 2021-02-17 05:18:07
问题 I am attempting to launch nvm within a child process in Nodejs on OSX However in doing so, I am getting the following error: /bin/sh: /Users/miker/.nvm/nvm.sh: Permission denied. child process exited with code 126 (I call the explicit path to nvm, since running without it, the child process can't see the executable.) This is obvious that it is a permission issue. However, I am not sure why since I can launch the commands on there own without issue. It is only when launching in a child process

JSON.stringify large object optimization

孤街浪徒 提交于 2021-02-17 05:08:13
问题 I'd like to convert a large JSON object to string using the JSON.stringify , but due to the size of the object I got an error of <--- Last few GCs ---> [20817:0x2cc2830] 295727 ms: Scavenge 1335.8 (1423.9) -> 1335.6 (1427.9) MB, 7.7 / 0.0 ms (average mu = 0.255, current mu = 0.170) allocation failure [20817:0x2cc2830] 295966 ms: Mark-sweep 1339.5 (1427.9) -> 1339.3 (1422.9) MB, 227.1 / 0.0 ms (average mu = 0.272, current mu = 0.291) allocation failure scavenge might not succeed [20817

Using self made npm package in react. Failed to compile

戏子无情 提交于 2021-02-17 04:59:12
问题 I followed https://zellwk.com/blog/publish-to-npm/ to create my custom npm package (https://www.npmjs.com/package/demo-to-publish). The folder structure of my custom package is as follows: src -> index.js node_modules List item Lable.js package.json webpack.config.js Content of my package.json is as follows: { "name": "demo-to-publish", "version": "1.0.5", "description": "testing publishing to npm", "main": "./src/index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1",