-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
40 lines (29 loc) · 861 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var express = require('express'),
sqlite3 = require('sqlite3').verbose(),
fs = require('fs'),
path = require('path')
;
var app = express();
var db = new sqlite3.Database(':memory:');
db.serialize(function() {
db.run("CREATE TABLE place (name TEXT, postcode TEXT)");
});
app.get('/search/:text', function(req, res){
var searchText = req.params.text;
});
app.get('/plans', function(){
db.all("SELECT * from place", [], function(err, rows){
if (!!err) res.json({error: err});
else res.json({data: rows});
});
});
app.post('/plans', function(){
var name = req.data.name;
var postcode = req.data.postcode;
db.run("INSERT INTO place VALUES (?)", [name, postcode]);
});
app.delete('/plans/:id')
app.use(express.static(__dirname + '/public'));
app.listen(3000, function () {
console.log('App listening on port 3000');
});