Skip to content

Commit

Permalink
Removed coffeescript completely. Added test directory with sample exp…
Browse files Browse the repository at this point in the history
…ress app. TODO: write proper unit tests
  • Loading branch information
Richard Girges committed Apr 22, 2016
1 parent ca393f0 commit f1d3c69
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Desktop.ini
node_modules
*.log
*.gz
test/uploadedfiles
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ app.post('/upload', function(req, res) {
}

sampleFile = req.files.sampleFile;
sampleFile.mv('/somewhere/on/your/server', function(err) {
sampleFile.mv('/somewhere/on/your/server/filename.jpg', function(err) {
if (err) {
res.status(500).send(err);
}
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@
"url": "https://github.com/richardgirges/express-fileupload/raw/master/LICENSE"
}
],
"repository": "richardgirges/express-fileupload"
"repository": "richardgirges/express-fileupload",
"devDependencies": {
"express": "^4.13.4"
}
}
12 changes: 12 additions & 0 deletions test/upload.test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<body>
<form ref='uploadForm'
id='uploadForm'
action='http://localhost:8000/upload'
method='post'
encType="multipart/form-data">
<input type="file" name="sampleFile" />
<input type='submit' value='Upload!' />
</form>
</body>
</html>
38 changes: 38 additions & 0 deletions test/upload.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var express = require('express'),
fileUpload = require('../lib/index.js'),
app = express();

app.use('/form', express.static(__dirname + '/upload.test.html'));

// default options
app.use(fileUpload());

app.get('/ping', function(req, res) {
res.send('pong');
});

app.post('/upload', function(req, res) {
var sampleFile, uploadPath;

if (!req.files) {
res.status(400).send('No files were uploaded.');
return;
}

sampleFile = req.files.sampleFile;

uploadPath = __dirname + '/uploadedfiles/' + sampleFile.name;

sampleFile.mv(uploadPath, function(err) {
if (err) {
res.status(500).send(err);
}
else {
res.send('File uploaded to ' + uploadPath);
}
});
});

app.listen(8000, function() {
console.log('Express server listening on port 8000');
})

0 comments on commit f1d3c69

Please sign in to comment.