Skip to content

Commit

Permalink
Basic functionaity
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleytodd committed Apr 27, 2013
0 parents commit e9cc3a5
Show file tree
Hide file tree
Showing 6 changed files with 1,068 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
38 changes: 38 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var http = require('http'),
fs = require('fs'),
csv = require('csv'),
connect = require('connect'),
Router = require('browserver-router');

var router = Router({
'/upload' : function(req, res) {
var json = {},
first = true;
fs.readFile(req.files['csv'].path, function(err, content) {
csv()
.from('' + content)
.on('record', function(row, index) {
if (first) {
json.headers = row;
json.data = [];
first = false;
} else {
json.data.push(row);
}
}).on('end', function() {
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(JSON.stringify(json));
});
});
}
});

var app = connect()

.use(connect.favicon())
.use(connect.static('public'))
.use(connect.directory('public'))
.use(connect.bodyParser())
.use(router);

http.createServer(app).listen(1234);
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "csv-view",
"version": "0.0.0",
"description": "A very simple CSV viewer",
"main": "index.js",
"repository": "",
"author": "Wes Todd",
"license": "BSD",
"dependencies": {
"csv": "~0.3.0",
"connect": "~2.7.6",
"browserver-router": "~0.1.1"
}
}
21 changes: 21 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link href='http://fonts.googleapis.com/css?family=Noto+Sans:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="/main.css">
</head>
<body>
<h1>Gimme dat file! <small>Drag it over me</small></h1>
<div id="container"></div>
<div id="overlay"></div>
<script src="/main.js"></script>
</body>
</html>
Loading

0 comments on commit e9cc3a5

Please sign in to comment.