我正在学习 Node.js。我正在创建一个像 Eventbrite 这样的网站。为了进行有效的模糊搜索,我正在实现fuse.js以通过EventName、Venue和一段时间来搜索事件date 。我不知道为什么我会收到这个错误。我该如何解决?
(节点:3672)[DEP0018] DeprecationWarning:不推荐使用未处理的承诺拒绝。
我在下面附上我的代码:
//Have a look in app.get()
const express = require('express');
const hbs = require('hbs');
const fs = require('fs');
const Fuse = require('fuse.js');
const MongoClient = require('mongodb');
const port = process.env.PORT || 5050;
var app = express();
var bodyParser = require('body-parser');
app.set('view engine', 'hbs');
hbs.registerPartials(__dirname + '/views/partials/');
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(bodyParser.json());
//to import json in db
//mongoimport --db Gather --collection Events --file JsonDataV2.txt --jsonArray
app.use(express.static(__dirname + '/public'));
let query;
let location;
//???? Getting problem here '/'
app.get('/',(req, res) => {
MongoClient.connect('mongodb://localhost:27017/Gathered',{ useNewUrlParser: true }, (err,client) => {
if(err){
return console.log('Unable to connect to MongoDb server.');;
}
try {
const db = client.db();
db.collection('Events').find().toArray().then((docs)=>{
console.log('query proccessed');
// Fuse.js implementation goes here...
var options = {
keys: ['EventName','Organiser','Venue','Time','Details']
};
var fuse = new Fuse(docs, options);
docs = fuse.search(query);
res.render('home.hbs',{
data: docs,
query:query,
location:location,
noOfResult:docs.length,
});
});
} catch (error) {
console.log(error);
}
client.close();
});
// res.render('home.hbs',{
// pageTitle: 'Home',
// welcomeMessage: 'Welcome to Home Page :)'
// });
});
app.post('/',function(req,res){
query = req.body.query; //recieve variable by name from frontend
location = req.body.location;
console.log("query: ",query);
console.log("location: ",location);
// res.send("Working");
});
app.listen(port, () => {
console.log(`Server is up at port ${port}`);
});