node.js - Can only access top level values in MongoDB response

I am using node to access data in MongoDB shown below, the document in my collection is this:{ "key_a" : "val_a", "key_b" : [ { "sub_b_keya" : "jenkins", "sub_b_keyb" : "foo" }, { "sub_b_keya" : "kubernetes/0", "sub_b_keyb" : "bar" } ] "key_c": 0}When i console log the response it prints everything just fine, but when i try to access the value at key, "sub_b_keya" it is undefined in the code below! Does the .toArray() not load sub documents into RAM, and only ...Read more

node.js - SocketIO Identify what user disconnected

I am making a simple Node.js game that uses Express, Socket.io, and an Http server. All of the users are stored in a multidimensional object on the server. This is how the server-side code works:var express = require('express');var app = express();var http = require('http').Server(app);var io = require('socket.io')(http);app.use(express.static(__dirname + '/'));var playerList = {};createPlayer = function(array,width,height,spdx,spdy,x,y,color,name,id) { var player = { width:width, height:height, spdx:spdx, spdy:spdy, x:x, y:y...Read more

node.js - Stripe webhook POST route does not have req.user

I am testing Stripe webhooks locally using ngrok, so that the webhooks can be sent to an endpoint on localhost. I want to test saving customer and payment information to my database, however, it seems like the middleware isn't attaching req.user (set by Passport) like it is on any other route. This makes it a lot less convenient in terms of accessing the authenticated user. I could do the database work on the routes where I receive a Stripe token, but the bulk of useful information is sent as a webhook. Another option is to save the charge id o...Read more

node.js - Error: update acceptor rejected

I switched my project (node.js + mongodb) from Openshift v2 to v3. Also I'm using Starter version of v3 for my project and web console for all configurations.Deploy results in failed status with following error:--> Scaling tmo-9 to 1error: update acceptor rejected tmo-9: pods for rc 'tmoolympus/tmo-9' took longer than 600 seconds to become availablePod's log:Environment: DEV_MODE=false NODE_ENV=production DEBUG_PORT=5858Launching via npm...npm info it worked if it ends with oknpm info using npm@3.10.9npm info using node@v6.11.3npm ...Read more

node.js - What are the possible causes for app deployed on heroku to get crashed?

I have a nodejs app.It builds successfully but then it crashes.The log says- 2016-07-28T11:41:39.150069+00:00 app[web.1]: at Function.Module._load (module.js:314:12) 2016-07-28T11:41:39.150070+00:00 app[web.1]: at startup (node.js:148:18) 2016-07-28T11:41:39.225296+00:00 heroku[web.1]: Process exited with status 1 2016-07-28T13:24:05.344533+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/?hub.mode=subscribe&hub.challenge=432092788&hub.verify_token=fb_bot" host=fb-121071064.herokuapp.com req...Read more

node.js - A better way to make a Node app run forever on a Linux server?

currently I use nohup and forever.js to run my app on the server (Linux) without interruption:nohup forever app.js > logs &plus I have a cron script that checks if my neo4j database is online and relaunches it if necessary.However, sometimes my app quits anyway and doesn't get relaunched.I read here that a better way of keeping a node.js running upstart and monit.Does anyone have experience doing that and is it really functioning better? What would be the commands to use to do that?Thank you!...Read more

node.js - Pass REST API data back to Node command line

I’m running this command: NODE_ENV=production grunt babel && NODE_ENV=sandbox node dist/bin/copilot.js --mode $1copilot.js launches another JavaScript file (depending on what the mode argument is in line above); in this case it’s copilotMonitor.jsThe short story is this ‘Monitor’ pings a REST API record, data is returned to it on if a mode needs to be restarted. The API will return something to copilotMonitor.js along the lines of "mode_3". How can I then pass this command pkill -9 -f <mode> back to the command line?I know process...Read more

node.js - "media type unrecognized" when uploading an image to Twitter using npm twit

I am working on an express node app that posts to twitter when a user inputs an image into a form. I am saving the image locally before uploading, which works. After I encode the file to base64, I try to upload the base64-encoded file to Twitter using twit's media/upload feature. When I do this, I get an error saying "media type unrecognized."Here is my code: app.post('/tweet', function(req, res){ var time = new Date().getTime() let image = req.files.image var imgpath = './images/img' + time + '.jpg' image.mv(imgpath, function(err) { ...Read more

node.js - CORS issue with Twitter api calls in Webpack dev server

I'm running into an issue getting responses from the twitter api (using npm package Twitter). In Chrome I am getting: Failed to load https://api.twitter.com/1.1/search/tweets.json?q=node.js: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 400. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS di...Read more

node.js - Does passport JWT strategy conflict with OAuth?

In my web app(node express), I use JWT to keep user's authentication status. Since I'm using JWT, I turned off session in passport config:passport.authenticate('jwt', { session: false });Now I need to integrate with Xero(or Twitter, whatever), OAuth Strategy comes to place as I need the user's authorization, following the three legged flow.However, when passport authenticates with OAuth strategy, error appears:Error: OAuthStrategy requires session support. Did you forget app.use(express.session(...))?Is the session in the error message the same...Read more

node.js - Winston-logger not working in modules

I have made a winston-module that I import into all modules that need logging. However it will only log entries in my application entry point(the one I start with).What have I done wrong with my implementation?logger.js (winston module)var winston = require('winston');var logger = new (winston.Logger)({ transports: [ new winston.transports.File({ filename: __dirname + '/logger.log', json: false, timestamp: function () { return new Date() } }) ], exceptionHandlers: [ new winston.transports.File({ filenam...Read more

node.js - Respond with a rich message as a Slack bot

I'm working on a Node.js slack app containing a bot user. But I don't know how to respond to a user with a rich message as a bot. Example:I can respond with simple messages without problems using this code:import * as SlackClient from '@slack/client';slackBot = new SlackClient.RtmClient(bot_access_token)slackBot.on(SlackClient.RTM_EVENTS.MESSAGE, message => { slackBot.sendMessage('Hello', message.channel);});slackBot.start();But RTM API doesn't support rich messages: The RTM API only supports posting simple messages formatted using our d...Read more

node.js - Slack bot not able to communicate after first dialog for other users

I have created a slack bot which works correctly on my machine, I have created prompts in slack bot and when the user clicks on the prompts the dialog(a type of form in slack) opens. Once the dialog is submitted another prompt comes up and corresponding dialog. I have attached the gif of the whole process.My issue is when another user in my slack workspace tries to communicate with the slack bot he gets the become a tutor form but once he submits that form he doesn't get the second prompt where he can add subjects. I have tried to host the appl...Read more

node.js - How can i get the response value from card buttons using hero card

I'm building a chat bot for products. I have a long list of products (each product display as card with the name only). I want the user to choose from the list which works fine but my issue is saving the data when the user is clicking on the product card. I don't see the data, any idea?var inMemoryStorage = new builder.MemoryBotStorage();var bot = new builder.UniversalBot(connector, function (session) { session.replaceDialog('chooseProduct');}).set('storage', inMemoryStorage);bot.dialog("chooseProduct",(session) => { var card = new bu...Read more