express

How to Pass Data Between Routes in Express

拟墨画扇 提交于 2020-01-02 08:39:32
问题 Suppose I have this POST route which receives some data. app.post('/getData', function(req, res){ var retrievedData = req.body.exampleVariable; // Send data to GET method }); And I have this GET method which renders a page, but needs the data I retrieved in the POST method app.get('/displayData', function(req, res){ // Retrieve data from POST method and display it. res.render('/examplePage.ejs', {retrievedData : req.retrievedData}); }); What is the best way to pass the retrievedData variable

How app.listen() and app.get() work on express and hapi

那年仲夏 提交于 2020-01-02 07:14:11
问题 With http node module (only native modules) how i can recreate app.listen() and app.get() use http module with a constructor var app = function(opts) { this.token= opts.token } app.prototype.get = function(callback) { // use request and response of app.listen() } app.prototype.active = function(callback) { // use request and response of app.listen() // return on callback some manipulate //request params } app.prototype.listen = function() { // start http or https server } Import the modules

how to create a simple node server that compresses static files using gzip

核能气质少年 提交于 2020-01-02 07:06:15
问题 I've been on this for hours.. the first thing i did was follow this tutorial which had this code: var express = require('express'); var app = express(); // New call to compress content app.use(express.compress()); app.use(express.static(__dirname + '/public')); app.listen(3333); naturally the code was outdated.. and I got this error: Error: Most middleware (like compress) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect

how to create a simple node server that compresses static files using gzip

£可爱£侵袭症+ 提交于 2020-01-02 07:06:03
问题 I've been on this for hours.. the first thing i did was follow this tutorial which had this code: var express = require('express'); var app = express(); // New call to compress content app.use(express.compress()); app.use(express.static(__dirname + '/public')); app.listen(3333); naturally the code was outdated.. and I got this error: Error: Most middleware (like compress) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect

transfer files between two node.js servers over http

跟風遠走 提交于 2020-01-02 06:57:09
问题 I have two node.js/express servers that communicate with each other with http. server A is also communicates with the browser and can handle file upload requests. When file is uploaded to server A i want to transfer it as is to server B for further processing. what is the best way to do so? preferably with request-promise module which is what i'm using for communication between the two servers. This is what i got so far, but i am unable to transfer the file between the servers, the file is

How to create basic authentication, login system for a web tool made in node.js and socket.io, without using express

会有一股神秘感。 提交于 2020-01-02 06:54:12
问题 I have a web tool developed, which uses node.js and socket.io. it's a one page website and uses node.js for getting data from social media website and display on the same page. I would like to add a site specific login system for the website but don't want to use 'Express' or 'Passport' as it adds lots of overload to the website while it is not needed. I am newbie with node.js and would like to know if I need to have a login system made with node.js to maintain session of the logged in user?

what does var io = require('../..')(server) do?

流过昼夜 提交于 2020-01-02 06:32:10
问题 I've build the project https://github.com/Automattic/socket.io/tree/master/examples/chat locally and it is working great. However, it would be nice to understand a little more about how a socket application works. In the main startup script one of the modules that is pulled in with require is var io = require('../..')(server) what does require('../..') do? thanks! 回答1: When a path to a directory is given to require , it will implicitly look for an index.js in that directory. In this case, it

Using express and es6 to render react and jsx server side

感情迁移 提交于 2020-01-02 06:13:55
问题 I am trying to wire up a minimum proof-of-concept to render a single React component server-side. When I run my app, I get an error: SyntaxError: express.js: Unexpected token (10:41) And the offending line is: > 10 | res.send(ReactDOMServer.renderToString(<Component msg={msg} />)); | ^ This is my package.json : { "name": "ssrReact", "version": "1.0.0", "main": "index.js", "license": "MIT", "scripts": { "start": "nodemon express.js --exec babel-node --presets es2015,stage-2" }, "dependencies":

Posting object array to sails causes 'TypeError: Cannot convert object to primitive value'

此生再无相见时 提交于 2020-01-02 05:39:08
问题 In my html page i am sending this post to my sails server but I cannot get to the data in my controller as the req.param() function does not return any meaningful answer. Here is the web page code $.post("http://myserver.local/calendar/batch", {"batch":[ { "start_date" : "2014-06-27T09:00:00Z", "title" : "abc", "attendees" : [ "Fred Bloggs", "Jimmy Jones", "The Queen" ], "event_id" : "123", "location" : "Horsham, United Kingdom", "end_date" : "2014-06-27T10:30:00Z" }, { "start_date" : "2014

Weird http request found in the Node.js Express log file

≯℡__Kan透↙ 提交于 2020-01-02 05:32:08
问题 my first public Node.js based web site (with Express) went to public couple weeks ago. I routinely checked the server log and sometimes there are some weird records. Here are some examples: - - - [Sat, 19 Oct 2013 08:44:38 GMT] "GET http://www.google.com/ HTTP/1.0" 200 3539 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" 222.205.7.245 - - [Sat, 19 Oct 2013 19:54:57 GMT] "GET http://www.wikipedia.org/ HTTP/1.1" 200 3539 "-" "Mozilla/5.0 (compatible; MSIE 5.01; Win2000)" 223.94.178.192