"Forest" and "Routes" folders not created on installation in express sequelize app

Feature(s) impacted

Anything that relies on editing in the folders (e.g., smart actions)

Observed behavior

The only file that was created when I followed the suggested installation process was .forestadmin-schema.json.

Expected behavior

I was expecting a “forest” directory to be created, and routes/[model name].js to be created.

Context

Here’s my server.js. I’m a novice programmer so it’s possible I’m missing something in my configuration, though I just followed the instructions that the onboarding gave me.

require('dotenv').config(); // Load environment variables from .env file
const express = require('express');
const morgan = require('morgan');
const logger = require('./config/logger.js');
const app = express();
const PORT = process.env.PORT || 3000;
const mainRoutes = require('./routes/routes');
const { setupGlobalPersistentMenu } = require('./controllers/fb-messenger-setup-services/globalPersistentMenuSetup');
const { setupWelcomePage } = require('./controllers/fb-messenger-setup-services/welcomePageSetup');
const cors = require('cors');

// CORS configuration
const corsOptions = {
  origin: '*', // Allow all origins
  methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
  optionsSuccessStatus: 204,
  credentials: true // Allow cookies
};

// Use the CORS middleware with the above options
app.use(cors(corsOptions));

// Forest Admin integration
const { createAgent } = require('@forestadmin/agent');
const { createSequelizeDataSource } = require('@forestadmin/datasource-sequelize');
const sequelizeInstance = require('./models').sequelize;
createAgent({
  authSecret: process.env.FOREST_AUTH_SECRET,
  envSecret: process.env.FOREST_ENV_SECRET,
  isProduction: process.env.NODE_ENV === 'production',
})
  .addDataSource(createSequelizeDataSource(sequelizeInstance))
  .mountOnExpress(app) // Replaced "myExpressApp" with "app"
  .start();

// Create a stream object with a 'write' function that will be used by `morgan`
logger.stream = {
  write: message => {
    // Use the 'info' log level to log HTTP requests
    logger.info(message.trim());
  }
};

// Use morgan middleware with the custom stream
app.use(morgan('combined', { stream: logger.stream }));

// Use express's raw middleware for the Stripe webhook route
app.use('/stripe/webhook', express.raw({type: 'application/json'}));

app.use(express.json()); // Parse JSON bodies

  // Setup global persistent menu for the Facebook bot
  setupGlobalPersistentMenu();
  
  // Setup welcome page for the Facebook bot
  setupWelcomePage();
  
  // Apply main application routes
  app.use(mainRoutes);
  
  // Basic endpoint for testing server status
  app.get('/', (req, res) => {
    res.send('Hello, World!');
  });


// Log Uncatched Exceptions
process.on('uncaughtException', (err) => {
  console.error('There was an uncaught error', err);
  process.exit(1); // mandatory (as per the Node.js docs)
});

// Log Uncatched Promise Rejections
process.on('unhandledRejection', (reason, promise) => {
  console.error('Unhandled Rejection at:', promise, 'reason:', reason);
  // Application specific logging, throwing an error, or other logic here
});

// Close any resources, such as database connections
process.on('SIGINT', () => {
  sequelizeInstance.close(); // Assuming sequelizeInstance is your Sequelize instance
  console.log('Connection pool closed gracefully');
  process.exit(0); // Exit the process with a success code
});

// Centralized error handler
app.use((err, req, res, next) => {
  logger.error(`Unhandled error: ${err.message}`);
  res.status(500).json({ message: 'An unexpected error occurred. Please try again later.' });
});

// Start the server and log the running status
app.listen(PORT, () => {
  logger.info(`Server running on port ${PORT}`);
});
  • Project name: Missionary Secretary (SEQUELIZE INTEGRATION)
  • Team name: Operations
  • Environment name: Development
  • Agent (forest package) name & version: @forestadmin/agent@1.16.2
  • Database type: Postgres
  • Recent changes made on your end if any: just installed forestadmin

Hi @trevorschoeny and welcome to the community !

The file that you have is created when using the agent-node-js which is the new generation of agent, and for sequelize project, is the agent by default since March 31 2023.
The implementation of what you have expected is the implementation in project using forest-express-sequelize.

Did you expect that from a previous project that you had or is it from the documentation ?

We have a documentation portal with the different agent types. And the documentation for your agent is here.

Best regards,

Shohan