Skip to content

Commit

Permalink
added basic json db
Browse files Browse the repository at this point in the history
  • Loading branch information
AashirSohail committed May 24, 2020
1 parent cdf8c36 commit d42ede1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
19 changes: 17 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
var express = require('express'); // call express
var app = express(); // define our app using express
var bodyParser = require('body-parser');
//var data = require('./responses.json');

// Declare variables
var fs = require('fs'),
obj

// Read the file and send to the callback
fs.readFile('./responses.json', handleFile)

// Write the callback function
function handleFile(err, data) {
if (err) throw err
obj = JSON.parse(data)
// You can now play with your datas
}

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
Expand All @@ -18,8 +33,8 @@ router.get('/', function(req, res) {
res.json({ message: 'welcome to our ADAM AI api!' });
});

router.get('/hi', function(req, res) {
res.json({ hi: 'Hello' });
router.get('/:id', function(req, res) {
res.send(obj);
});

app.use('/api', router);
Expand Down
6 changes: 6 additions & 0 deletions responses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"hi": "Hello",
"How are you": "I am good, Thank you",
"Hello":"Hello",
"What is your name":"My name is ADAM AI"
}

0 comments on commit d42ede1

Please sign in to comment.