ScaffoldHub - v2
  • Introduction
  • Modeling
    • Two-way Relationships
  • Setup
    • Backend
    • Frontend
    • File Storage
    • Emails with SendGrid
    • Payments with Stripe
  • Debugging
  • Deployment
    • Database
      • SQL
      • MongoDB
    • Backend
      • Google Cloud - App Engine
      • Google Cloud - Run
      • Under construction...
    • Frontend
      • Firebase Hosting
      • Heroku w/ Subdomains
      • Under construction...
  • Features
    • Projects
    • Preview
    • Tenants
      • Single-Tenant
      • Multi-Tenant
      • Multi-Tenant (w/ subdomains)
    • Payments
    • Security
    • Authentication
      • Sign-in and Sign-up
      • Invitation
      • Password Reset
      • Password Change
      • Email Verification
    • Audit Logs
    • Settings
    • Internationalization (I18n)
    • Entity
      • Form
      • Filter and List
      • Export
      • Import
    • API Documentation
  • Architecture
    • Security
    • File Storage
    • Internationalization (I18n)
    • Payments
    • Typescript Support
    • Rate limiting
    • Technologies Versions
    • Under construction...
  • Recipes
    • Testing the API with Postman
    • Enterprise sign-in with WorkOS
    • Under construction...
  • Support
  • Changelog
    • Documentation
    • Scaffolds
  • Custom Development
  • Legacy Scaffolds
  • Go to ScaffoldHub
Powered by GitBook
On this page
  • Installing NodeJS
  • Installing the Database
  • Configuring .env variables
  • SQL version
  • MongoDB version
  • JWT secret and expiration
  • Frontend URL
  • Email configuration
  • File Storage
  • Social Sign-in
  • Payments configuration (Optional)
  • Installing the Dependencies
  • Creating the database
  • Running the backend server

Was this helpful?

  1. Setup

Backend

PreviousSetupNextFrontend

Last updated 2 years ago

Was this helpful?

The configuration for the backend is located at the backend/.env file.

Installing NodeJS

Make sure you have installed on your machine. The recommended version is 16.

Is recommended that you use a Node Version Manager tool for you to be able to switch version if you need it in the future.

MacOS/Linux:

Windows:

Installing the Database

Please make sure you have the database of your choice installed and running on your machine.

Also, make sure you have access to that database using a database GUI tool.

ScaffoldHub supports:

  • (for the SQL version)

  • (for the SQL version)

  • (for the MongoDB version)

Configuring .env variables

The .env file is located at backend/.env and it stores the environment variables.

SQL version

If you are using the default PostgreSQL database on your localhost, you can leave the configuration as it is.

You must have the DATABASE_DATABASE created on your localhost server. The default config uses development as the database name.

DATABASE_USERNAME = "postgres"
DATABASE_DIALECT = "postgres"
DATABASE_PASSWORD = ""
DATABASE_DATABASE = "development"
DATABASE_HOST = "localhost"
DATABASE_LOGGING = "true"

For MySQL, use those settings:

DATABASE_USERNAME = "root"
DATABASE_DIALECT = "mysql"
DATABASE_PASSWORD = ""
DATABASE_DATABASE = "development"
DATABASE_HOST = "localhost"
DATABASE_LOGGING = "true"

MongoDB version

For the MongoDB version, you must place the full connection URL.

The default example uses the localhost server and the development schema.

# Connection URL for Mongoose
# See https://mongoosejs.com/docs/index.html
DATABASE_CONNECTION = "mongodb://localhost:27017/development"
    
# In case you want to use ACID transactions, follow this doc:
# https://mongoosejs.com/docs/transactions.html
DATABASE_TRANSACTIONS = false

JWT secret and expiration

The JWT secret is used to sign the JWT tokens. Please replace the JWT secret to some random and long UUID chain. For example: a40a8850-24b2-4023-85ce-1765d10c849b-758df0c2-b112-4851-960d-1b7163d3ccd6

The JWT expiration invalidates the tokens after a certain period that can be configurated on the AUTH_JWT_EXPIRES_IN variable.

# Secret used to Sign the JWT (Authentication) tokens.
AUTH_JWT_SECRET = "GENERATE_SOME_RANDOM_UUID_HERE"
# How long the JWT (Authentication) token takes to expire.
AUTH_JWT_EXPIRES_IN = "7 days"

Frontend URL

For localhost, the frontend URLs will be:

  • http://localhost:3000 (for React)

  • http://localhost:8081 (for Vue)

  • http://localhost:4200 (for Angular)

Same ports for the FRONTEND_URL_WITH_SUBDOMAIN. Please leave the [subdomain] as it is. Note: This works only for the multi-with-subdomain tenant mode.

# Frontend Url.
# Ex.: http://localhost:<port>
FRONTEND_URL="http://localhost:<port>"

# Frontend URL with the subdomain for tenants.
# Works only for tenantMode=multi-with-subdomain
# Please use the variable [subdomain] on this URL.
FRONTEND_URL_WITH_SUBDOMAIN="http://[subdomain].localhost:<port>"

Email configuration

File Storage

Localhost

By default, files are stored on the localhost.

Cloud

Social Sign-in

Social sign-in is pre-configured for Google and Facebook. What you have to do is to fill the AUTHSOCIAL* env variables with the secrets you get on your Google and Facebook developer accounts.

AUTH_SOCIAL_GOOGLE_CLIENT_ID = ""
AUTH_SOCIAL_GOOGLE_CLIENT_SECRET = ""
AUTH_SOCIAL_GOOGLE_CALLBACK_URL = "http://localhost:8080/api/auth/social/google/callback"

AUTH_SOCIAL_FACEBOOK_CLIENT_ID = ""
AUTH_SOCIAL_FACEBOOK_CLIENT_SECRET = ""
AUTH_SOCIAL_FACEBOOK_CALLBACK_URL = "http://localhost:8080/api/auth/social/facebook/callback"

Payments configuration (Optional)

Installing the Dependencies

Go to the backend folder of your project and run:

npm install

You can ignore installation warnings.

Creating the database

For the SQL version: ScaffoldHub disables foreign keys to avoid problems with recursivity that some modelings may have. To enable foreign keys, search by constraints: false in the backend and change the flags to true. Note: Relationships to models.filemust keep the constraints: false.

Go to the backend folder of your project and run:

npm run db:create

For SQL: This command will create all the tables.

If the following error occurs, you need to set a password in your database and change the DATABASE_PASSWORD in the .env file with the created password.

For MongoDB: This command will create all the collections and the indexes. If you skip this step, the app will work, but throw errors where you have unique validation defined.

Running the backend server

Go to the backend folder of your project and run:

npm start

The standard localhost server does not support , but you probably want it enabled in production. You can rent a database, point your localhost to it, and enable the DATABASE_TRANSACTIONS flag. That way you ensure you are developing on the same conditions of your future production environment.

For the email configuration, follow the section.

For the premium version, you can set Google Cloud Storage or Amazon S3 providers, by following the section.

Google:

Facebook:

For payment configuration, follow the section.

If the following error occurs, you need to set a password in your database and change the DATABASE_PASSWORD in the .env file with the created password.

NodeJS
https://github.com/nvm-sh/nvm
https://github.com/coreybutler/nvm-windows
PostgreSQL
MySQL
MongoDB
Emails with SendGrid
File Storage
https://console.cloud.google.com/apis/credentials/oauthclient
https://developers.facebook.com/
Payments with Stripe
"TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument must be of type string or an instance of Buffer, TypedArray, DataView, or KeyObject. Received null"
ACID transactions
cloud-hosted MongoDB