@mahjongg/mern-mvc

1.4.0 • Public • Published

Instructions:

This package relies on Yarn, so be sure that you have it installed globally.

npm install yarn -g

Next, install this package,

npm install -g @mahjongg/mern-mvc

Navigate to the desired location for your new project and run:

mern-mvc create <project-name>

mern-mvc will create a new folder for you with the name specified. This name will also be used in your package.json, so it must follow some naming conventions as required by npm. Only lowercase letters, numbers, or the "-" symbol are allowed.

What's Included?

mern-mvc creates an application that uses the following on the backend:

"dependencies": {
    "express",
    "express-session",
    "mongoose",
    "passport",
    "passport-local",
    "passport-local-mongoose"
  },
  "devDependencies": {
    "concurrently",
    "jest",
    "nodemon"
  }

All packages are installed at their most recent versions. It includes fully set-up user authentication, with the option for more fields to be added with ease.

You can opt out of passport set-up by using the flag --no-passport (aliased as -x).

A react application will be created using create-react-app, in a folder called 'client'. The dev dependencies concurrently and nodemon are used to allow both the react server and api server to be run in parallel when using yarn start. The react-app utilizes react-router-dom for routing, and axios for AJAX calls.

The React app has some very basic authentication forms included, but you are free to implement authentication however you like.

Route builder:

mern-mvc now includes a command for building a simple route file!

mern-mvc route <name> --options

The <name> parameter is used to determine the folder name to put the new route file in. You will still need to include that file somewhere and attach it to a specific path. Options include: --no-passport (-p): This will leave passport out of the function argument on your new route file. --no-functionBased (-f): This will create your route file so that it exports the Router object directly, rather than exporting a function that returns the Router. --routes (-r): This allows you to include a list of paths you want in your route. For simplicity, they are all created as GET routes, although it is simple enough to change them to some other method. The value provided to the --routes option should be include in double quotes and separated by a comma and a space. For example: mern-mvc route users --routes "signIn, signUp, signOut"

Will produce this file: users/index.js

module.exports = function(passport) {
	const router = require('express').Router();

	router.get("/signIn",function(req,res){

	});

	router.get("/signUp",function(req,res){

	});

	router.get("/signOut",function(req,res){

	});

    return router;
};

TODO:

other options to add to create command...

  • -r | no-react (for when the user has a premade react app)
  • -s | simple-routes (routes files are created as simple exports, rather than functions)
  • -n | no-npm (skips npm install, for quicker creation on slow connections. Still writes to package.json)

Package Sidebar

Install

npm i @mahjongg/mern-mvc

Weekly Downloads

6

Version

1.4.0

License

ISC

Unpacked Size

102 kB

Total Files

28

Last publish

Collaborators

  • mahjongg