Skip to content

Backend

Musanje Louis Michael edited this page Oct 21, 2020 · 5 revisions

Backend coding and maintenance reference

File structure for the backend:

Project
├── Server.js
├── App.js
├── .gitignore
├── README.md
├── package.json
├── yarn.lock
├── .env
├── Routes
   └── index.js
├── Controllers
   └── index.js
├── Database
   └── index.js
├── Models
   └── index.js
├── Helpers
   └── index.js
  • All functions will be imported to their respective index.js files that reside in the same folders and exported from there after
  • Arrow functions will be preffered over Legacy functions style
For example
// This is the preffered arrow function style.
const xFunction = () => {
   // function body here.
}

// Instead of this legacy function style.
function xFunction() {
   // function body.
}

  • Exporting function style would be preferred as below
// first function.
const xFunction = () => {}
// second function.
const yFunction = () => {}

... other functions

// and export functions as below
module.exports = { xFunction, yFunction, ...other functions };
  • Below is a structure of files in one folder.
// for example Routes folder.
Routes
├── Users.js
├── Comments.js
└── index.js

in the index.js file

const {...functions from Users.js} = require('./Users.js');
const {...functions from Comments.js} = require('./Comments.js');

modules.exports = { ...Users.js functions, ...Comments.js };
  • The .env file will contain all necessary private credentials and should never be pushed to github. The variables will be shared appropriately as needed.

  • Commenting will be based on the standard documentation Found Here. Both single line and Multi-line comments are accepted as long as they are descriptive.

/** this is a multi
line comments */

// this is a single line comment

//Example of multiline comment describing function
/**
 * Function adds title of book and author
 * @param {string} title - The title of the book.
 * @param {string} author - The author of the book.
 * @returns {string} Concatenation of title and author
 */
const Book = (title, author) => {
// function body
}

// Simplest form of documenting a function with it's description of what the function does.
/** This is a description of the foo function. */
cont foo = () => {
// function body
}

Important Vscode plugin you might need to ease your work in one environment.

  • Vscode rest-client. This plugin replaces postman allowing you to make api requests right from vscode.
  • Mongodb playground for vscode. This plugin makes it easy for you to easily browse mongodb databases whether local or remote easily in a single file in a fly.
  • Nodejs Extension pack. This one contains most of the tools needed to quicken dev't in Nodejs. Like linting, syntax highlighting, intellisense etc..

Clone this wiki locally