Forest: Your server encountered an error

I’m trying to run a server programmed in NodeJS. The server runned fine when deployed on Heroku and used forest as an admin. Now I’m trying to run that same server locally, with forest locally as well. The DB is a local MongoDB.

So I run my server and it is able to connect with an app I made perfectly. It connects to the mongoDB database properly as well. So then I want to use Forest Admin. I install Forest admin (I create a new project on the website and follow the npm install instructions). I can then run it with npm start and I’m able to see my DB properly.

The problem comes when I run my server which uses forest-express-mongoose. What happens is that when I run it, it somehow corrupts Forest or something and Forest UI shows me Your server encountered an error .

Here’s my server’s code.

My package.json:

"dependencies": {
  "async": "^2.6.2",
  "body-parser": "^1.18.3",
  "cors": "^2.8.5",
  "dotenv": "^6.2.0",
  "express": "^4.16.4",
  "forest-express-mongoose": "^2.16.1",
  "mongodb": "^3.1.13",
  "mongoose": "5.1.4",
  "mongoose-schema-extend": "^0.2.2"

I’m aware I’m using some old dependencies but if I start changing them, the project starts having issues.

Maybe I’m using the wrong approach and I have to launch the forest server from the same app instead of following forest’s instructions when I create a new project? Cause it seems that forest when first launched modeled after what was populated inside my DB and then when I run my server it remodeled it. However if I empty my DB, the same thing happens.

I posted this same question in stackoverflow but I didn’t get an answer so I was hoping somebody here could help me.
Thanks in advance.

Hi @Alejandro and welcome in our community :wave: !

I can’t seem to access your server’s code :thinking:

And I don’t understand that part:

Yopu have your lumber project running but you are trying to start another server that also uses forest-express-mongoose ? Did I get it right ?

What do you mean by the same app :thinking: ? You have 2 apps connected to Forest Admin :thinking: ?

@vince Thank you.

This is the issue I’m having. I have my server programmed in NodeJS that uses forest-express-mongoose. I’m lost on how to connect this with a forest admin panel. The server runs well but then when I go to the Forest webpage I don’t know how to link a project with my server.

When I go to Forest I’m required to create a new project and follow the steps over there which make me install another desktop app to interact with forest. That’s what I find weird, why am I not able to connect Forest directly with my server?

Since I was unable to do that, I followed the instructions and run that Forest Admin app on my computer and then my server. And that produces the error mentioned above.

Here’s my server’s code.

const express = require('express');
const bodyParser = require('body-parser');
// create express app
const app = express();
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }))
// parse application/json
// Configuring the database
const dbConfig = require('./config/database.config.js');
const mongoose = require('mongoose');
const cors = require('cors');
mongoose.Promise = global.Promise;
// Connecting to the database
mongoose.connect(process.env.MONGODB_URI || dbConfig.url, {
    useNewUrlParser: true
}).then(() => {
    console.log("Successfully connected to the database");
}).catch(err => {
    console.log('Could not connect to the database. Exiting now...', err);
// define a simple route
app.get('/', (req, res) => {
    res.json({"message": "Welcome to EasyDonations application. Take donations quickly. Organize and keep track of all your donations."});
// Then use it before your routes are set up:
app.use(cors({credentials: true, origin: true}));
// listen for requests
app.listen(process.env.PORT || 3000, () => {
    console.log("Server is listening on port 3000");
    modelsDir: __dirname + '/app/models',
    envSecret: 'xxx', // I'm hiding my key, but it is the one I get at the development environment of forest
    authSecret: 'testeando', // I think I can put any string for development purposes, otherwise I don't know were to get authSecret
    mongoose: require('mongoose'),

Hmm if you have already a project you juste need to go to the Project Settings, click on environment tabs and create a new development environment.

If that’s not the case, you could try to just copy the FOREST_ENV_SECRET that have been generated on your newly generated project and paste it on your old project. And try to run ONLY your old project.
Does it work ?

Thank you very much, the first one was it. :grinning: