Mongoose syntax error

Asked

Viewed 105 times

1

I am trying to create an application using express.js and mongodb, when I try to run the server this syntax error appears. The error that appears refers to a zero-only document (Ex: 0000 0000 0000 0000), I’m a Noob in the field.

D:\teste de apps\mean\node_modules\mongoose\node_modules\mongodb\lib\rea  
d_preference.js:1                                                         
(function (exports, require, module, __filename, __dirname) {             
                                                              ^           
SyntaxError: Unexpected token ILLEGAL                                     
    at Module._compile (module.js:439:25)                                 
    at Object.Module._extensions..js (module.js:474:10)                   
    at Module.load (module.js:356:32)                                     
    at Function.Module._load (module.js:312:12)                           
    at Module.require (module.js:364:17)                                  
    at require (module.js:380:17)                                         
    at Object.<anonymous> (D:\teste de apps\mean\node_modules\mongoose\l  
ib\utils.js:5:16)                                                         
    at Module._compile (module.js:456:26)                                 
    at Object.Module._extensions..js (module.js:474:10)                   
    at Module.load (module.js:356:32) 

//MEAN-APP/config/Mongoose.js

var config = require('./config');
var mongoose = require('mongoose');

module.exports = function(){
    var db = mongoose.connect(config.db);
    require('../app/models/user.server.model');
    return db;
};

//MEAN-APP/config/env/Development.js

module.exports = {
    db: 'mongodb://localhost/mean-book',
    // Development configuration options
    // the sessionSecret string can be anything
    sessionSecret: 'developmentSessionSecret'
}

//MEAN-APP/server.js

process.env.NODE_ENV = process.env.NODE_ENV || 'development';

var mongoose = require('./config/mongoose');
var express = require('./config/express');

var db = mongoose();
var app = express();

app.listen(3000);

module.exports = app;

console.log('Server running at http://localhost:3000/');

//MEAN-APP/config/express.js

var session     = require('express-session'),
    config      = require('./config'),
    express     = require('express'),
    morgan      = require('morgan'),
   compress     = require('compression'),
 bodyParser     = require('body-parser'),
 methodOverride = require('method-override'),
    mongoose    = require('mongoose');

module.exports= function(){
    var app = express();
    if(process.env.NODE_ENV === 'development'){
        app.use(morgan('dev'));
    } else if (process.env.NODE_ENV ==='production'){
        app.use(compress());
    }
    app.use(bodyParser.urlencoded({
        extended : true
    }));

    app.use(bodyParser.json());
    app.use(methodOverride());

    app.use(session({
        saveUninitialized: true,
        resave: true,
        secret: config.sessionSecret
    }));

    app.set('views', './app/views');
    app.set('view engine', 'ejs');

    require('../app/routes/index.server.routes.js')(app);

    app.use(express.static('./public'));

    return app;
}
  • You need to add more code and explain what is happening. Putting only the error here gives no margin to help. And please write in Portuguese. Isn’t that parenthesis too much? or do you have an IIFE with (function (exports, require, module, __filename, __dirname) { ...})()?

  • I am trying to create an application using express.js and mongodb, when I try to run the server this syntax error appears. The error that appears refers to a document with only zeros(Ex: 0000 0000 0000 0000), I am a Noob in the matter.

  • Can you [Edit] the question to join details. When did the bug? change any lines? can you put the code you are doing?

  • The error appeared exactly when trying to connect the database with express

  • //Mongoose.js var config = require('./config'); var Mongoose = require('Mongoose'); module.Exports = Function(){ var db = Mongoose.connect(config.db); require('./app/models/user.server.model'); Return db; };

  • Sérgio when I see where the error appears, I open the document and this is what appears in ' Mean node_modules Mongoose node_modules mongodb lib rea d_preference.js:1': 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 00000000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 I have no idea where that IIFE is located.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.