Git Product home page Git Product logo

express_psql_boilerplate's Introduction

GIT-USERNAME-HERE REPO-NAME-HERE APP-NAME-HERE PUT-TECH-STACK-HERE API-DEPLOY-URL-HERE

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

APP-NAME-HERE - Server

PUT-TECH-STACK-HERE
Explore the docs »

Report Bug · Request Feature?


APP-NAME-HERE


This will be a comprehensive README for the sake of both prospective employers and fellow cohort peers, and whomever else would be interested in some of the techniques I've learned creating my frist Fullstack application. As a bonus, this README has some interesting implementations, though I won't address them here.

If you'd like to test the server via Postman, visit the client app...

...register a user, grab your Bearer Token in dev tools, and use this endpoint: https://glacial-basin-85263.herokuapp.com/setapp/v1



This README will systematically go over the entire app from the top level to the bottom layer, so I'll provide links to various sections for convenience.

TODO - ADD DIRECTORY LINKS!


db:

migrations, seeds

Nothing much to say here, simple SQL code to seed the database


src:

server.js:

Bog-standard setup using Knex

config.js:

I use this to configure all environment variables and export them from a single source. You can then access these via destructured imports:

const { NODE_ENV } = require('./config');

app.js:

Most of the setupp here is standard, with some particular use of conditionals and environment variables to configure middleware options. Note the absence of importing express, I'll get to that a little later...

Barrels...

You may have already noticed that there are actually many [ index.js ] files peppered throughout the app. These are known as "barrel" exports, and have a few advantages when dealing with a complex file-directory. The index file in the [ routes ] folder has a short explanation, but I'll also put it here:

/*
|--------------------------------------------------------------------------
| BARREL EXPORT FILE
|--------------------------------------------------------------------------
| How-To barrel-export components:
| const thingsRouter = require('./things/thingsRouter')
|
| module.exports = {
|   thingsRouter
| }
|
| Why? Readability:
| const { thingsRouter, stuffRouter, userRouter } = require('./routes')
*/
const usersRouter = require('./users.router');

module.exports = {
  usersRouter
};

You can see this in action in [ app.js ]:

TODO!!!

Note that the import doesn't point to the index file. Node perceives [ index.js ] files as points of entry and the default file to grab exports from, essentially making it an implicit file in import statements


constants:

Not strictly necessary, but this can help prevent typos, along with making changes to the database less tedious to update throughout the app.


libs:

A simple Winston logger, though bacause Heroku doesn't support writing logs in this way, the transports aren't created during production.


middlewares:

express-methods.js:

Though it may be inconsequential for a server of this scale, it should be known that every time you import a package from node_modules there's a memory cost at runtime, made worse by doing a destructured import. Express is costly to import (~750K unzipped), so I came up with this method here, resulting in importing Express only once in my entire server.

I can create both the app and jsonBodyParser (which is just middleware), and extract the Router() method itself (to be used as a sort of local "helper" function). Beacuase these are now local dependencies, I can import these wherever I want without an impact on runtime performance.

body-validators.js:

These are used to extract and validate request body values on a per-route basis, serialize any user-inputs, then creates a completed object passing it on to the next middleware. There are a few helper-functions at the top to DRY up the code a bit.

auth.js, error-handlers.js:

There's nothing too special here, just basic Token authentication, password encryption, and error handling/formatting.


routes:

A brief overview of the database:
erm

This isn't 100% representative of the current database implementation, but from a relationship view this is how the Server operates. Currently, the following tables are implemented: users, songs, sets, songs_sets


services:


Contact

Github - musicMan1337

Facebook - Derek Nellis

Instagram - @derek.8bit.nellis

express_psql_boilerplate's People

Contributors

musicman1337 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.