Skip to content

reubennn/nextgen-limitless-server

Repository files navigation

Next Gen Limitless Server

This repo contains the code for the back-end server files for the Next Gen Limitless fullstack website. This is so we can automatically deploy our server to a hosting service capable of running Node.js applications, such as Heroku. The back-end utilises Express.js to act as a server API which queries the database from MongoDB.

An Ongoing Project

Currently, this is a simple blog website. However, this is an ongoing project with the aim to add further features down the line, as well as convert it a full website with the blog section only one part of it.

Libraries Used

Popular libraries used include:

  • Express.js to provide the back-end web application framework.
  • nodemon to reload the server automatically after any saved changes.
  • body-parser middleware to parse request bodies.
  • helmet to help secure the Express app by setting various HTTP headers.
  • MongoDB Client to interact with MongoDB using native Node.js driver.
  • Luxon.js to quickly and efficiently format dates.
  • dotenv to load confidential information as environment variables into process.env, to keep it hidden from Git.

Getting Started

Setting up Environment Variables

The URI, database name and collection names have not been provided in Git due to confidentiality of data. These would be stored in secrets.env located in config/. You can find an example file containing mock keys-value pairs in secrets.env.example. You have two options to populate the data:

  1. Replace MONGO_URI, DB_NAME, ARTICLES and AUTHORS, COMMENTS with the URI, database name and collection names, respectively.
  2. Create a file called secrets.env inside config/ and populate it with the appropriate data:
MONGO_URI=mongodb+srv://<user>:<password>@<database>?retryWrites=true&w=majority
DB_NAME=database-name
ARTICLES=article-collection
AUTHORS=author-collection
COMMENTS=comments-collection
PORT=9000

Integrating with MongoDB

The data is hosted on MongoDB Atlas cloud using MongoDB Client Node.js Driver.

Inside the server/ directory, files have been provided to set-up the database with initial data. Initial data can be found in articles.js and comments.js; the files to import the content into the database are addArticlesToDB.js and addCommentsToDB.js.

Simply run npm run db-setup to upload all data as documents to MongoDB.

Alternatively, you can upload just the articles, or just the comments using npm run db-setup:articles or npm run db-setup:comments, respectively.

Running the React App

For information on running the client, please see the Next Gen Limitless repo.

Running the Express.js Server

Simply run npm run server. The server will run on http://localhost:9000.

Running Express.js Server Without Client react-dev-server

We can serve the static files by bundling the files to the server dist/ directory using webpack to generate a production build.

For information on generating the production build, please see the Next Gen Limitless repo.

Other

Linting

The server uses its own linting configuration, achieved through ESLint. This keeps the code clean, written correctly and ensures it uses industry best practices.

The server uses rules extended from:

  • eslint:recommended
  • prettier
  • google

Transpiling

Both server and client use their own transpiling configuration, achieved through Babel, to use next generation JavaScript language features.

Original Content from LinkedIn Learning Course

About

Server API files for the Next Gen Limitless website.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published