Skip to content

Commit 0436dfd

Browse files
committed
make the node.js sample work on Windows
1 parent 7ef333a commit 0436dfd

4 files changed

Lines changed: 222 additions & 216 deletions

File tree

samples/Node.js/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Sample code for Node.js
22

3-
This sample is written for [Node.js 0.6+](http://nodejs.org/) and requires [Express](http://expressjs.com/) to make the sample code cleaner.
3+
This sample is written for [Node.js](http://nodejs.org/) and requires [Express](http://expressjs.com/) to make the sample code cleaner.
44

55
To install and run:
66

77
cd samples/Node.js
8-
npm install express
8+
npm install
99
node app.js
1010

1111
Then browse to [localhost:3000](http://localhost:3000).

samples/Node.js/app.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1+
process.env.TMPDIR = 'tmp'; // to avoid the EXDEV rename error, see http://stackoverflow.com/q/21071303/76173
2+
13
var express = require('express');
24
var multipart = require('connect-multiparty');
35
var multipartMiddleware = multipart();
4-
var flow = require('./flow-node.js')('tmp/');
6+
var flow = require('./flow-node.js')('tmp');
57
var app = express();
68

79
// Host most stuff in the public folder
810
app.use(express.static(__dirname + '/public'));
911
app.use(express.static(__dirname + '/../../src'));
1012

1113
// Handle uploads through Flow.js
12-
app.post('/upload', multipartMiddleware, function(req, res){
13-
flow.post(req, function(status, filename, original_filename, identifier){
14-
console.log('POST', status, original_filename, identifier);
15-
res.send(200, {
16-
// NOTE: Uncomment this funciton to enable cross-domain request.
17-
//'Access-Control-Allow-Origin': '*'
14+
app.post('/upload', multipartMiddleware, function(req, res) {
15+
flow.post(req, function(status, filename, original_filename, identifier) {
16+
console.log('POST', status, original_filename, identifier);
17+
res.send(200, {
18+
// NOTE: Uncomment this funciton to enable cross-domain request.
19+
//'Access-Control-Allow-Origin': '*'
20+
});
1821
});
19-
});
2022
});
2123

2224
// Handle cross-domain requests
@@ -31,15 +33,15 @@ app.post('/upload', multipartMiddleware, function(req, res){
3133
*/
3234

3335
// Handle status checks on chunks through Flow.js
34-
app.get('/upload', function(req, res){
35-
flow.get(req, function(status, filename, original_filename, identifier){
36-
console.log('GET', status);
37-
res.send(200, (status == 'found' ? 200 : 404));
38-
});
36+
app.get('/upload', function(req, res) {
37+
flow.get(req, function(status, filename, original_filename, identifier) {
38+
console.log('GET', status);
39+
res.send(200, (status == 'found' ? 200 : 404));
40+
});
3941
});
4042

41-
app.get('/download/:identifier', function(req, res){
42-
flow.write(req.params.identifier, res);
43+
app.get('/download/:identifier', function(req, res) {
44+
flow.write(req.params.identifier, res);
4345
});
4446

45-
app.listen(3000);
47+
app.listen(3000);

0 commit comments

Comments
 (0)