express

Can't get Express session ID from cookies w/ Socket.IO

戏子无情 提交于 2020-01-01 08:01:30
问题 I have a typical web application in Node that is utilizing the Express framework and the session middleware. I am also using Socket.io for certain dynamic parts of my application (currently, this is a chat mechanism, but that's tangential). I've been able to successfully set up sessions and socket.io on their own, but would like to combine them (EG: to associate socket chat messages with user accounts without hitting the database). It should be noted (and I can see this being a possible issue

How can I send back response headers with Node.js / Express?

十年热恋 提交于 2020-01-01 07:45:11
问题 I'm using res.send and no matter what, it returns status of 200. I want to set that status to different numbers for different responses (Error, etc) This is using express 回答1: res.writeHead(200, {'Content-Type': 'text/event-stream'}); http://nodejs.org/docs/v0.4.12/api/http.html#response.writeHead 回答2: For adding response headers before send, you can use the setHeader method: response.setHeader('Content-Type', 'application/json') The status only by the status method: response.status(status

MEAN.js Social Sharing?

烈酒焚心 提交于 2020-01-01 06:18:19
问题 So I built an app using MEAN.js, and I made some updates to the Articles (blog) section for better SEO, readability, design, etc. One problem I can't seem to figure out, though, is how to share the Articles using Facebook, Google+, Twitter, etc. and have them populate the right data using og meta tags. WHAT I WANT All I want is to be able to share Articles (blog posts) from my MEAN.js application, and have the article content show up when I post the link in Social sites (e.g. Facebook). WHAT

MEAN.js Social Sharing?

Deadly 提交于 2020-01-01 06:15:19
问题 So I built an app using MEAN.js, and I made some updates to the Articles (blog) section for better SEO, readability, design, etc. One problem I can't seem to figure out, though, is how to share the Articles using Facebook, Google+, Twitter, etc. and have them populate the right data using og meta tags. WHAT I WANT All I want is to be able to share Articles (blog posts) from my MEAN.js application, and have the article content show up when I post the link in Social sites (e.g. Facebook). WHAT

Node.js: How to properly return an object from within a callback?

送分小仙女□ 提交于 2020-01-01 06:11:25
问题 Still wrapping my head around callbacks. What's the proper way to define/return an object from within a callback function? You can see my 2 console.logs in the following snippet, the one outside of the callback is of course undefined, how do I define it? In my app.js: var tools = require('../models/tools.js'); app.get('/games', requireAuth, function (req, res) { var gameqlist = tools.getMyGameQs(req, function(err, gameqlist){ console.log(gameqlist); // this is properly defined return

Node.js: How to properly return an object from within a callback?

谁说我不能喝 提交于 2020-01-01 06:11:12
问题 Still wrapping my head around callbacks. What's the proper way to define/return an object from within a callback function? You can see my 2 console.logs in the following snippet, the one outside of the callback is of course undefined, how do I define it? In my app.js: var tools = require('../models/tools.js'); app.get('/games', requireAuth, function (req, res) { var gameqlist = tools.getMyGameQs(req, function(err, gameqlist){ console.log(gameqlist); // this is properly defined return

How do I return a value from a simple jsdom function?

一世执手 提交于 2020-01-01 05:39:25
问题 I'm using jsdom with jquery, and it's working just fine. However, I'm trying to modularize my code a bit so I don't repeat myself, so I made a basic function out of some jsdom code that takes in some html (DOM), tweaks it with jquery, and spits it back out. However, I'm unable to return my result and thus assign it to a calling var. I'm probably not returning in the right place, but I'm just not seeing the obvious if so. Could use a little help. Here's the code: function tweakIt(html_in){ var

How can I replace the default favicon in an slc loopback generated webapp?

给你一囗甜甜゛ 提交于 2020-01-01 05:29:08
问题 I have generated an app using slc loopback command. So the generated express webapp has its strongloop favicon. How can I change the favicon? I am using this in server.js app.use(loopback.favicon(path.resolve(__dirname, '../client/favicon.ico'))); I also tried with html link tag, but still default is loading. What am I doing wrong? 回答1: Set the path to your custom favicon in the server/middleware.json : { "initial:before": { "loopback#favicon": { "params": "path/to/your/favicon.ico" } }, … We

Getting webpack hot updating to work correctly in my isomorphic web app

可紊 提交于 2020-01-01 05:25:07
问题 I'm creating a webapp with a node/express backend and a react frontend. I got (I think) most of it up and running, but the last step of getting the browser to perform a hot refresh does not work as intended. I'll try to post all the relevant setup here. Please let me know if you require anything else to find out where I have done a mistake: I start up my application with node ./server/index.js webpack.config.js var path = require('path'); var webpack = require('webpack'); let webpackConfig =

Use process.on('uncaughtException to show a 500 error page

≯℡__Kan透↙ 提交于 2020-01-01 05:23:19
问题 I'm developing an express app. I currently have the following in my server.js process.on('uncaughtException', function (err) { console.log( "UNCAUGHT EXCEPTION " ); console.log( "[Inside 'uncaughtException' event] " + err.stack || err.message ); }); Which stops the server crashing every time there's an error, however, it just sits there... is it possible to instead of console.log, to send a 500 error page with the error details? 回答1: I don't think you can from within the uncaughtException do