Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript SyntaxError:模块处的输入意外结束。\u编译_Javascript_Node.js_Mongodb - Fatal编程技术网

Javascript SyntaxError:模块处的输入意外结束。\u编译

Javascript SyntaxError:模块处的输入意外结束。\u编译,javascript,node.js,mongodb,Javascript,Node.js,Mongodb,我正在尝试为我的服务器运行以下节点JS代码 但它在第74行给出了err,但所有代码在第72行完成 我的代码是 server.js var express = require("express"), app = express(), bodyParser = require('body-parser'), errorHandler = require('errorhandler'), methodOverride = require('method-override

我正在尝试为我的服务器运行以下节点JS代码

但它在第74行给出了err,但所有代码在第72行完成

我的代码是

server.js

var express = require("express"),
    app = express(),
    bodyParser = require('body-parser'),
    errorHandler = require('errorhandler'),
    methodOverride = require('method-override'),
    hostname = process.env.HOSTNAME || 'localhost',
    port = parseInt(process.env.PORT, 10) || 4004,
    publicDir = process.argv[2] || __dirname + '/public';
var exec = require('child_process').exec;
var fs = require('fs');
var MongoClient = require('mongodb').MongoClient
    , format = require('util').format;


  MongoClient.connect('mongodb://127.0.0.1:27017/prisync', function(err, db) {
  if (err) throw err;
    console.log("Connected to Database");

//Show homepage
app.get("/", function (req, res) {
  res.redirect("/index.html");
  console.log("shubham ");
});
app.get("/index/", function (req, res) {
  res.redirect("/index.html");
  console.log("shubham ");
});

app.get("/search", function (req, res){
  console.log("shubham batra");
   var pro_name = req.query.name;
   var pro_code = req.query.code;
   var pro_category = req.query.category;
   var pro_brand = req.query.brand;

   console.log(name);
   console.log(code);
   console.log(category);
   console.log(brand);



    var documen = {name:pro_name, code:pro_code , category:pro_category, brand:pro_brand };

  //insert record
  db.collection('urlinfo').insert(documen, function(err, records) {
    if (err) throw err;
    console.log("Record added as "+records[0]._id);
  });

   //res.send('You sent the name "' + req.body.name + '".');
  console.log(res.body);
  res.redirect("/index.html");
});
app.use(errorHandler({
  dumpExceptions: true,
  showStack: true
}));
//Search page
app.use(methodOverride());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
  extended: true
}));
app.use(express.static(publicDir));
app.use(errorHandler({
  dumpExceptions: true,
  showStack: true
}));

console.log("Server showing %s listening at http://%s:%s", publicDir, hostname, port);
app.listen(port);
当我尝试运行此代码时,出现以下错误:


您尚未正确关闭代码块:

MongoClient.connect('mongodb://127.0.0.1:27017/prisync', function(err, db) {
  if (err) throw err;
  console.log("Connected to Database");
  // The rest of your code that needs `db` should go here
});

您尚未正确关闭代码块:

MongoClient.connect('mongodb://127.0.0.1:27017/prisync', function(err, db) {
  if (err) throw err;
  console.log("Connected to Database");
  // The rest of your code that needs `db` should go here
});