Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added basic json db #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}