LogoLogo
  • Introduction
  • Backend
    • Creating a MongoDB Database
    • Environment Variables
    • Configuring the Mailing Service
    • Seeding the Database
    • Starting the Backend
  • Frontend
    • Starting the Frontend
  • Book Module Tutorial
    • Introduction
    • Backend
      • Create Model
      • Create Service
      • Create Route
      • Test using Postman
    • Frontend
      • Introduction
      • File Structure
      • Defining Concepts
      • Display App in Dashboard
      • Create Module
      • Create Book List Component
      • Create Main Component
      • Create Service
      • Display Book List
      • Add a Book
        • Update Service
        • Create Component
        • Final Code Review
      • Delete a Book
        • Update Service
        • Update Component
        • Final Code Review
      • Conclusion
  • Resources
  • Beginner
  • Advanced
  • Recommended Extensions for Visual Studio Code
  • Troubleshooting
    • Troubleshooting
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Backend

Starting the Backend

If you have successfully completed the previous sections, your .env file should look like this:

.env
# APP #
SITE_NAME = SMUPortal
APP_SECRET = YgTP8SVHvLYWTn4E3aaM9tXPw8x-lInKCfFO10ZQWBo
REFRESH_TOKEN = 1UKfOmU5rlhan2wnkyjQGkK2sNaJCE-rPS-hOls5Wlk
TOKEN_EXPIRES_IN = 1h

# Email domain names should be seperated by a vertical bar (used in regex)
EMAIL_DOMAINS = medtech.tn|msb.tn|smu.tn

# DB #
DB_URL = <DB-CONNECTION-STRING>

# NodeMailer #
# SMTP_USER should contain an email not a username
SMTP_SERVICE = gmail
SMTP_USER = <EMAIL-ADDRESS>
SMTP_TYPE = OAuth2

# Google OAuth
G_CLIENT_ID = <CLIENT-ID>
G_CLIENT_SECRET = <CLIENT-SECRET>
G_ACCESS_TOKEN = <ACCESS-TOEKN>
G_REFRESH_TOKEN = <REFRESH-TOEKN>
G_REDIRECT_URI = https://developers.google.com/oauthplayground

Do not forget to replace all placeholders (e.g. <CLIENT-ID>) with their correct values.

We are all set to start the backend code.

First, install the dependencies using npm i command.

~/smuportal-backend (master)
npm i

Once that is finished, you can start the server using npm start and you should get the following output

~/smuportal-backend (master)
npm start

> smuportal@0.0.0 start ~/smuportal-backend
> nodemon server.js

[nodemon] 2.0.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server.js`
Server is up
Connection to DB established!

That's it! The backend server is now running. If you are comfortable enough with backend technologies you can start developing, or you can browse the following sections where we go through a small example of a backend service.

Happy coding 🎉!

PreviousSeeding the DatabaseNextStarting the Frontend

Last updated 4 years ago

Was this helpful?

If for some reason you got a different output, please make sure that you have correctly followed the instructions from previous sections or you can open an .

issue