节点js错误。有专家吗?

时间:2015-12-08 12:54:07

标签: node.js

我是nodejs的新手。我遇到了这个错误,现在我无法启动我的npm。请让我知道如何重新启动npm以及如何防止遇到此问题

错误如下:

{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }

js-bson: Failed to load c++ bson extension, using pure JS version
C:\Users\sriramr\nodetest1\routes\index.js:129
collection.find({},{}function(e,docs){
                     ^^^^^^^^
SyntaxError: Unexpected token function
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (C:\Users\sriramr\nodetest1\app.js:11:14)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)

npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program     Files\\nodejs
\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v0.12.0
npm ERR! npm  v2.5.1
npm ERR! code ELIFECYCLE
npm ERR! nodetest1@0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nodetest1@0.0.0 start script 'node ./bin/www'.
npm ERR! This is most likely a problem with the nodetest1 package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node ./bin/www
npm ERR! You can get their info via:
npm ERR!     npm owner ls nodetest1
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\sriramr\nodetest1\data\npm-debug.log

消息来源代码:: INDEX.JS

var express = require('express');
var router = express.Router();

router.get('/', function(req, res, next) {

res.render('index',{title:'欢迎来到会议室演示。'});     });

router.get('/userlist', function(req, res) {
var db = req.db;
var collection = db.get('usercollection');
collection.find({},{},function(e,docs){
    res.render('userlist', {
        "userlist" : docs
    });
});
});


router.get('/newuser',function(req,res){
res.render('newuser',{title:'Add new user'});
});
router.get('/newuser',function(req,res){
res.render('newroom',{title:'Add new room'});
});


router.post('/adduser', function(req, res) {


var db = req.db;


var userName = req.body.username;
var userEmail = req.body.useremail;


var collection = db.get('usercollection');


collection.insert({
    "username" : userName,
    "email" : userEmail
}, function (err, doc) {
    if (err) {

        res.send("There was a problem adding the information to the     database.");
    }
    else {

   res.redirect("userlist");
    }
});
});
/*---------adding room number and room list -------*/
router.post('/addroom', function(req, res) {

var db = req.db;
var roomname = req.body.roomname;
var collection = db.get('roomlist');
collection.insert({
    "roomname" : roomname

}, function (err, doc) {
    if (err) {
        res.send("There was a problem adding the information to the database.");
    }
    else {
        res.redirect("roomlist");
    }
});
});
/*----------room end list ------------------*/
/*--------addingtime list ----------*/
router.post('/addtime', function(req, res) {
var db = req.db;
var starttime = req.body.strt_time;
var endtime = req.body.end_time;
var emailid = req.body.empemail;
var collection = db.get('timelist');
collection.insert({
    "starttime" : starttime,
    "endtime" : endtime,
    "emailid": emailid

}, function (err, doc) {
    if (err) {
        res.send("There was a problem adding the information to the     database.");
    }
    else {
        res.redirect("addtime");
    }
});

  var collection = db.get('roomlist');
collection.find({},{},function(e,docs){
    res.render('roomlist', {
        "roomname" : roomname
    });
});

});
/*---------removing time list --------*/
/*----removing room number and roomlist -----------*/
router.post('/removeroom', function(req, res) {

    var db = req.db;
    var roomname = req.body.remove_room;
    var collection = db.get('roomlist');
    collection.remove({
        "roomname" : roomname

    }, function (err, doc) {
        if (err) {
            res.send("There was a problem adding the information to the     database.");
        }
        else {
            res.redirect("roomlist");
        }
    });
});




router.get('/roomlist', function(req, res) {
var db = req.db;
var collection = db.get('roomlist');
collection.find({},{}function(e,docs){
    res.render('roomname', {
        "roomname" : docs
    });
    });
});

/*----------end room number and room list ---------*/
/*--end db connection for user ---*/
module.exports = router;

1 个答案:

答案 0 :(得分:2)

我不会&#39;认为这是一个Node.js问题,只是Javascript。

据报道,似乎打破了这一切的代码是:

collection.find({},{},function(e,docs){

基本上,您不允许在&#34; {}&#34;之后立即提供功能。如果您的列表中的参数是&#34;找到&#34;方法调用你的&#34;集合&#34;对象,你应该添加一个逗号,简单如下:

router.get('/roomlist', function(req, res) {
  var db = req.db;
  var collection = db.get('roomlist');
  collection.find({},{},function(e,docs){  // your error fixed!!!
    res.render('roomname', {
        "roomname" : docs
    });
  });
});

/*----------end room number and room list ---------*/
/*--end db connection for user ---*/
module.exports = router;

固定版本(index.js文件的底部):

<vermarktungsart ERBPACHT="false" KAUF="true" MIETE_PACHT="false" />