A quick and easy way to create Nodejs websites with MVC architecture.
Note: When going trough how it works we will use a Blog Application example. It will only be an API
The Websites entry point is main.ts from there it adds all the routes to the app which it gets from either API.ts or WEB.ts in the Routes directory Inside the API.ts/WEB.ts it imports all routes from Routes/api or Routes/web depending on if it's a web or api controller.
in the routes file it will have:
routes.get("/", PostsController.Index);
routes.post("/", PostsController.Store);
routes.get("/:id", PostsController.Show);
routes.put("/:id", PostsController.Update);
routes.patch("/:id", PostsController.Update);
routes.delete("/:id", PostsController.Destroy);.
├── src
│ ├── Controllers
│ │ └── PostsController.ts
│ ├── Models
│ │ └── Post.ts
│ ├── Routes
│ │ ├── API.ts
│ │ └── api
│ │ └── PostRoutes.ts
│ ├── Utils
│ │ ├── ErrorHandeling.ts
│ │ └── Str.ts
│ └── main.ts
├── package.json
└── tsconfig.jsonCreating
mvc-creator create project <name>Creating
mvc-creator create controller <name>Flags:
- -e : --everything, Creates a Model, Controller and Routes
- -a : --api, Only creates API methods (Excluding: Edit and Create)
Creating
mvc-creator create model <name>Creating
mvc-creator create middleware <name>Creating
mvc-creator create util <name>Creating
mvc-creator create error <name>Creating
mvc-creator create envGenerate App key
mvc-creator env key generateView App Key
mvc-creator env key viewView Value
mvc-creator env get <key>Set Value
mvc-creator env set <key> <value>Generate random string for Value
mvc-creator env generate <key>Remove Value
mvc-creator env remove <key>Show entire file
mvc-creator env show- Make so any dotenv operation changes the .env.example file
- Split things into files to remove clutter and copy-code