-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.js
38 lines (32 loc) · 927 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 : 'your database'
});
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 TABLE 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));
});
});
app.listen(4000, () => {
console.log(App listening on port ${ PORT });
console.log('Press Ctrl+C to quit.');
});