-
Notifications
You must be signed in to change notification settings - Fork 2
/
Server.js
38 lines (31 loc) · 911 Bytes
/
Server.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
var express=require('express');
var app=express();
var mysql=require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '',
database : 'autocomplete_search'
});
connection.connect();
app.set('views',__dirname + '/views');
app.use(express.static(__dirname + '/JS'));
app.set('view engine', 'ejs');
app.engine('html', require('ejs').renderFile);
app.get('/',function(req,res){
res.render('index.html');
});
app.get('/search',function(req,res){
connection.query('SELECT first_name from user_name where first_name like "%'+req.query.key+'%"', function(err, rows, fields) {
if (err) throw err;
var data=[];
for(i=0;i<rows.length;i++)
{
data.push(rows[i].first_name);
}
res.end(JSON.stringify(data));
});
});
var server=app.listen(3000,function(){
console.log("We have started our server on port 3000");
});