I'm using addon mongoDB and it was working locally and remotely on Heroku 
until I added mongoose. It is still working locally but not remotely with 
mongoose. It is giving me an error of missing a curly { brace. I have used 
VIM and Atom to make sure and they are matching and it works locally. My 
index.js is 100 lines long but the logs from Heroku say the error at the 
index.js file is on line 117. It also seems to be in a directory called 
app/index.js. I don't have the corresponding directory on my local machine. 


Any suggestions of how to fix it and/or look at the code on the Heroku 
remote site? 



Here's the error:



017-08-18T17:20:22.817662+00:00 heroku[web.1]: Process exited with status 1

2017-08-18T23:04:55.394915+00:00 heroku[web.1]: State changed from crashed 
to starting

2017-08-18T23:04:56.891483+00:00 heroku[web.1]: Starting process with 
command `node index.js`

2017-08-18T23:04:59.182099+00:00 app[web.1]: /app/index.js:117

2017-08-18T23:04:59.182118+00:00 app[web.1]: });

2017-08-18T23:04:59.182120+00:00 app[web.1]:     at createScript 
(vm.js:56:10)

2017-08-18T23:04:59.182119+00:00 app[web.1]: SyntaxError: Unexpected token }

2017-08-18T23:04:59.182120+00:00 app[web.1]:     at Module._compile 
(module.js:542:28)

2017-08-18T23:04:59.182118+00:00 app[web.1]: ^

2017-08-18T23:04:59.182121+00:00 app[web.1]:     at Module.load 
(module.js:487:32)

2017-08-18T23:04:59.182120+00:00 app[web.1]:     at Object.runInThisContext 
(vm.js:97:10)

2017-08-18T23:04:59.182122+00:00 app[web.1]:     at Function.Module._load 
(module.js:438:3)

2017-08-18T23:04:59.182123+00:00 app[web.1]:     at Module.runMain 
(module.js:604:10)

2017-08-18T23:04:59.182121+00:00 app[web.1]:     at 
Object.Module._extensions..js (module.js:579:10)

2017-08-18T23:04:59.182122+00:00 app[web.1]:     at tryModuleLoad 
(module.js:446:12)

2017-08-18T23:04:59.182123+00:00 app[web.1]:     at run 
(bootstrap_node.js:389:7)

2017-08-18T23:04:59.182124+00:00 app[web.1]:     at startup 
(bootstrap_node.js:149:9)

2017-08-18T23:04:59.279042+00:00 heroku[web.1]: State changed from starting 
to crashed

2017-08-18T23:04:59.266161+00:00 heroku[web.1]: Process exited with status 1

2017-08-19T00:26:03.451573+00:00 heroku[router]: at=error code=H10 
desc="App crashed" method=GET path="/" host=safe-hamlet-88602.herokuapp.com 
request_id=d074a2ed-275e-411f-a1c8-ef0249744621 fwd="71.212.102.71" dyno= 
connect= service= status=503 bytes= protocol=https

2017-08-19T00:26:04.131734+00:00 heroku[router]: at=error code=H10 
desc="App crashed" method=GET path="/favicon.ico" 
host=safe-hamlet-88602.herokuapp.com 
request_id=f2030928-5b26-4dde-995e-1a2098cfc132 fwd="71.212.102.71" dyno= 
connect= service= status=503 bytes= protocol=https


Here's the index.js file:


const cool = require('cool-ascii-faces');

const express = require('express');

const app = express();

const pg = require('pg');

const bodyParser = require('body-parser');

var mongodb = require('mongodb');

var mongoose = require('mongoose');


/*

*  require file-system so that we can load, read, require all of the model 
files

*/

    fs = require('fs'),


app.set('port', (process.env.PORT || 5000));


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


// .json will parse out the JSON information from the AJAX call

app.use(bodyParser.json());


// views is directory for all template files

app.set('views', __dirname + '/views');

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


//var uri ='mongodb://localhost/test';

var uri = process.env.MONGODB_URI;


mongoose.connect(uri);

console.log(uri);


var TestSchema = mongoose.Schema({

    id: { type: Number, required: true, minlength: 1},

    name: { type: String, required: true, minlength: 4}

});


//mongoose.model('test', TestSchema);

mongoose.model('test_collection, TestSchema');


var test = mongoose.model('test_collection', TestSchema, 'test_collection');



app.get('/', function(request, response) {

  response.render('pages/index');

});


app.get('/cool', function(request, response) {

  response.send(cool());

});


app.get('/times', function(request, response) {

    var result = '';

    var times = process.env.TIMES || 5;

    for (i=0; i < times; i++)

        result += i + ' ';

    response.send(result);

});


app.get('/db', function(request, response){

    pg.connect(process.env.DATABASE_URL, function(err, client, done) {

        client.query('SELECT * FROM test_table', function(err, result) {

            done();

            if(err)

            {

                console.log(err);

                response.send("Error " + err);

            }

            else {

                response.render('pages/db', {results: result.rows} );

            }

        });

    });

});


app.get('/mongo', function(request, response){


    // Standard URI format: mongodb://[dbuser:dbpassword@]host:port/dbname


//    var uri = "mongodb:// (I'm commenting this out)

    var uri = process.env.MONGODB_URI;

    console.log(uri);


//    mongodb.MongoClient.connect(uri, function(err, db) {

    //    var data = db.collection("test_collection");



                 test.find({}, function( err, result) {

                     if (err) {

                        console.log(err);

                        res.send(err);

                    } else {

                //    response.render('pages/mdb', {result.name} );

                    console.log(result + result.length);

                    response.json(result);

            //        db.close();

                }

            });

});


app.listen(app.get('port'), function() {

  console.log('Node app is running on port', app.get('port'));

});


Here's the package.json file:

{
  "name": "node-js-getting-started",
  "version": "0.2.6",
  "description": "A sample Node.js app using Express 4",
  "engines": {
    "node": "6.11.1"
  },
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "cool-ascii-faces": "1.3.4",
    "ejs": "2.5.6",
    "express": "4.15.2",
    "mongodb": "^2.2.30",
    "mongoose": "^4.11.7",
    "pg": "6.x"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/heroku/node-js-getting-started";
  },
  "keywords": [
    "node",
    "heroku",
    "express"
  ],
  "license": "MIT"
}

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Heroku" group.

To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/heroku?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"Heroku Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to