Git Product home page Git Product logo

mongoose-liquid-express-boilerplate's Introduction

General Assembly Logo

mongoose-express-liquid-boilerplate

A template for starting full stack projects with express. Includes authentication, example resource and common middlewares.

Installation

  1. Download this template as a .zip file. DO NOT FORK AND CLONE
  2. Move the .zip file to your sei/projects/ directory and Unzip it (creating a folder) -- NOTE: if the folder was already unzipped, use the mv command line to move it to the sei/projects/ directory.
  3. Rename the directory from mongoose-express-liquid-boilerplate -> your-app-name.
  4. Find and Replace any mention of mongoose-express-liquid-boilerplate especially the one in package.json
  5. Empty README.md and fill with your own content.
  6. Move into the new project and git init if not already a repository.
  7. Run touch .env in the main project directory(same level as server.js)
  8. Add node_modules and .env to your .gitignore if it's not already there(it should be)
  9. Replace all example models, controllers, and views with your app's resources. Auth is provided for you already.
  10. Install dependencies with npm install.
  11. Ensure that you have nodemon installed by running npm install -g nodemon.
  12. In your .env add variables for PORT & DATABASE_URL & SECRET. This app uses mongoDb and Session authentication, so your DATABASE_URL will need to be your local mongo(see the full CRUD app's .env for reference)
  13. Ensure the API is functioning properly by running npm start.
  14. Once everything is working, make an initial commit.
  15. Add features on other branches and merge them into the main branch as you complete them!

Structure

Dependencies are stored in package.json.

The most important file for understanding the structure of the template is server.js. This is where the actual Express app object is created, where the routes are registered, and more. To register a routefile, follow the pattern established here with exampleRoutes and userRoutes. If you want to add any middlewares to your app, add it to the file utils/middleware.js in the main export function, which is called in server.js.

The main directory contains models, views, and controller files. Models are simply Mongoose models. To create your own, follow the patterns established in models/example.js. Similarly, the controllers and views listed under the examples directories are a great starting point for your own resources.

The models/connection.js file holds all mongoose connection setup steps and can be required and destructured from just like this (Schema and model given as examples):

const { Schema, model } = require('./connection.js')

You probably will only need to interact with files in /models, /controllers, /views and server.js.

Tasks

This template uses npm as a task runner. These are the commands available:

Command Effect
npm start Starts a development server with nodemon that automatically refreshes when you change something.

Documenting

Use this as the basis for your own documentation. Add a new third-level heading for your custom entities, and follow the pattern provided for the built-in user authentication documentation.

Authentication

Verb URI Pattern Controller#Action
POST /auth/signup users#signup
POST /auth/login users#login
DELETE /auth/logout/ users#logout

Error Handling

Errors are handled with a default view, and should be called as seen in this example:

router.delete('/:id', (req, res) => {
	const exampleId = req.params.id
	Example.findByIdAndRemove(exampleId)
		.then(example => {
			res.redirect('/examples')
		})
		.catch(error => {
			res.redirect(`/error?error=${error}`)
		})
})
  1. All content is licensed under a CC­BY­NC­SA 4.0 license.
  2. All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact [email protected].

mongoose-liquid-express-boilerplate's People

Contributors

timmshinbone 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.