Backend

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

Installing NodeJS

Make sure you have NodeJS 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: https://github.com/nvm-sh/nvm

Windows: https://github.com/coreybutler/nvm-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:

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.

The standard localhost server does not support ACID transactions, but you probably want it enabled in production. You can rent a cloud-hosted MongoDB 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.

# 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

For the email configuration, follow the Emails with SendGrid section.

File Storage

Localhost

By default, files are stored on the localhost.

Cloud

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

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)

For payment configuration, follow the Payments with Stripe section.

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.

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. "TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument must be of type string or an instance of Buffer, TypedArray, DataView, or KeyObject. Received null"

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

Last updated