diff --git a/david_park/.gitignore b/david_park/.gitignore new file mode 100644 index 0000000..902b281 --- /dev/null +++ b/david_park/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +data/ diff --git a/david_park/hi.json b/david_park/hi.json new file mode 100644 index 0000000..b1759f7 --- /dev/null +++ b/david_park/hi.json @@ -0,0 +1 @@ +utf8 \ No newline at end of file diff --git a/david_park/package.json b/david_park/package.json new file mode 100644 index 0000000..65dbec2 --- /dev/null +++ b/david_park/package.json @@ -0,0 +1,20 @@ +{ + "name": "david_park", + "version": "1.0.0", + "description": "", + "main": "server.js", + "dependencies": { + "body-parser": "^1.14.1", + "express": "^4.13.3" + }, + "devDependencies": { + "chai": "^3.4.1", + "mocha": "^2.3.3" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node server.js" + }, + "author": "", + "license": "ISC" +} diff --git a/david_park/server.js b/david_park/server.js new file mode 100644 index 0000000..697b83f --- /dev/null +++ b/david_park/server.js @@ -0,0 +1,38 @@ +var express = require('express'); +var app = express(); +var http = require('http'); +var fs = require('fs'); +var bodyparser = require('body-parser'); + +//data coming in from a post request should be saved to a json file +//in "data" directory. Do not commit your data file to git. +// '/*' means any URL +app.post('/*', function(req, res) { + var filepath = (__dirname + "'data' + req.url.slice(1) + '.json'"; //slice removes char(0) + console.log(filepath); + fs.writeFile(filepath, /*POSTDATA?*/, function(err, data) { //fs.writeFile(file, data[, options], callback) + if (err) return throw err; + console.log('it\'s saved!'); + + /*req.pipe().?*/ + + }); +}) + +//pipe ondata tostring +//take json data and directly pipe it (req.pipe) + +app.get('/', function(req, res) { + res.send('Get request received!'); +}); + +app.get('/*', function(req, res) { + var route = req.url; + console.log(route); + fs.readFile('data' + route + '.json'); // +}) + +app.listen(3000, function () { + console.log('server up'); +}); + diff --git a/david_park/test/app_test.js b/david_park/test/app_test.js new file mode 100644 index 0000000..90da0e1 --- /dev/null +++ b/david_park/test/app_test.js @@ -0,0 +1,7 @@ +var chai = require('chai'); +var expect = chai.expect; +require(__dirname + '/../server'); + +describe('', function () { + +})