jewel-cloud1-cecelia-zieme
v1.0.0
Published
A full fledge template to create react-npm-package on the fly. This template took care of CI/CD setup of that package as well.
Downloads
5
Readme
Quick Start Node
Welcome to Quick Start Node, a template repository to kickstart your Node.js projects with a solid foundation and best practices.
Project Overview
Quick Start Node provides a generic starting point for your Node.js projects, complete with a well-organized project structure, common dependencies, and essential configurations. It's designed to help you save time and ensure consistency across your projects.
Getting Started
Follow these steps to get your project up and running:
- Clone this repository to your local machine.
- Navigate to the cloned directory:
cd quick-start-node
. - Install dependencies:
npm install
. - Customize the env code or change it as needed. Copy example.json and paste the content in three files: development.json, production.json and test.json:
cat ./env/example.json | tee ./env/development.json ./env/production.json ./env/test.json > /dev/null
. - Start the server:
npm run start
Usage
This template covers the basic structure and setup of a Node.js project. You can adapt it for various types of applications:
- Define your routes and controllers in the
src/routes
andsrc/controllers
directories. - Model your data and schema in the
src/models
directory. - Utilize middleware functions in the
src/middleware
directory. - Expand your application logic in the
index.js
file.
Customization
- Dependencies: Add or remove dependencies by modifying the package.json file.
- Configuration: Adjust configuration settings in the env/ directory. Copy all code from example.json file to new files
development.json
,test.json
andproduction.json
in same directory and add or change the data. You can run this in in your package root alsocat ./env/example.json | tee ./env/development.json ./env/production.json ./env/test.json > /dev/null
. - Scripts: Customize scripts in the package.json file to match your development workflow.
Testing and Development
- Start the development server:
npm run dev
. - Run unit tests:
npm run test:unit
- Run integration tests:
npm run test:integration
- Set up additional testing configurations in the tests directory.
Tech Stack and Dependencies Used.
- Node Js
- Express Js
- Mongo DB
For other dependencies please check package.json file.
Project Structure
You can use these commands to print your project tress:
CMD:
tree /A /F | findstr /V /C:"node_modules"
POWERSHELL:
Get-ChildItem -Recurse | Where-Object { $_.FullName -notlike "*\node_modules\*" } | ForEach-Object { $_.FullName }
UBUNTU (WSL):
tree --prune -I 'node_modules' --dirsfirst
ortree -a -I 'node_modules|.git' --dirsfirst
quick-start-node/
├── .github
│ └── workflows
│ └── build-lint-test.yml
├── .vscode
│ ├── extensions.json
│ └── settings.json
├── env
│ ├── development.json
│ ├── example.json
│ ├── production.json
│ └── test.json
├── logs
│ ├── error.log
│ ├── uncaught-exceptions.log
│ └── unhandled-rejections.log
├── public
│ ├── data
│ │ ├── http-status-codes.js
│ │ └── programming-error-codes.js
│ ├── images
│ │ ├── avatar1.png
│ │ └── avatar2.png
│ └── styles
│ └── index.min.css
├── src
│ ├── assets
│ │ └── scss
│ │ ├── _about-us.scss
│ │ ├── _contact-us-email-template.scss
│ │ ├── _contact-us.scss
│ │ ├── _footer.scss
│ │ ├── _header.scss
│ │ ├── _home.scss
│ │ ├── _page-not-found.scss
│ │ ├── _variables.scss
│ │ └── index.scss
│ ├── configurations
│ │ ├── index.js
│ │ ├── logger.js
│ │ ├── mongo-atlas.js
│ │ ├── nodemailer.js
│ │ └── set-environment-config.js
│ ├── controllers
│ │ ├── auth-controller.js
│ │ ├── index.js
│ │ ├── pages-controller.js
│ │ ├── reset-password-controller.js
│ │ └── user-controller.js
│ ├── middlewares
│ │ ├── async-error-handler.js
│ │ ├── index.js
│ │ ├── is-authenticated-middleware.js
│ │ ├── is-valid-object-id-middleware.js
│ │ ├── log-request-info-middleware.js
│ │ ├── uncaught-errors-middleware.js
│ │ ├── use-middlewares.js
│ │ └── validate-and-sanitize-request-middleware.js
│ ├── models
│ │ ├── Temporary-Token.js
│ │ ├── User.js
│ │ └── index.js
│ ├── routes
│ │ ├── auth-route.js
│ │ ├── index.js
│ │ ├── pages-route.js
│ │ ├── reset-password-route.js
│ │ └── user-route.js
│ ├── utilities
│ │ ├── format-error.js
│ │ ├── format-response.js
│ │ ├── get-project-name.js
│ │ ├── index.js
│ │ └── string-utilities.js
│ ├── validators
│ │ ├── auth-validators.js
│ │ ├── index.js
│ │ ├── pages-validators.js
│ │ ├── reuseable-validators.js
│ │ └── user-validators.js
│ └── views
│ ├── components
│ │ ├── footer-mixin.pug
│ │ └── header-mixin.pug
│ ├── emails
│ │ └── email-template.pug
│ ├── about-us.pug
│ ├── contact-us.pug
│ ├── home.pug
│ └── page-not-found.pug
├── tests
│ ├── integration
│ │ └── routes
│ │ └── user.test.js
│ ├── unit
│ │ ├── configs
│ │ │ └── mongo-atlas.test.js
│ │ ├── middlewares
│ │ │ └── is-authenticated.test.js
│ │ └── models
│ │ └── User.test.js
│ └── setup.js
├── .eslintrc.json
├── .gitignore
├── LICENSE
├── README.md
├── index.js
├── package-lock.json
└── package.json
Conventions
Naming
- Variables: Utilize camelCase when naming variables.
- Files:
- Apply kebab-case for file names (e.g.,
is-authenticated-user.js
). - In cases of repetitive file names, consider appending the folder name to improve clarity and organization.
- For example, if "user" appears in multiple places, name files as
user-route.js
,user-controller.js
,user-middleware.js
.
- For example, if "user" appears in multiple places, name files as
- Apply kebab-case for file names (e.g.,
- Classes:
- Opt for PascalCase when naming classes (e.g.,
User
). - The files containing classes should follow PascalCase + kebab-case (e.g.
User-Class.js
).
- Opt for PascalCase when naming classes (e.g.,
File Organization
The project employs a meticulous folder structure to uphold a neat and methodical codebase:
/public
: Serves as the repository for static files./env
: Hosts environment and confidential files, catering to various environments. Files such asdevelopment.json
,test.json
, andproduction.json
are ignored; however, an illustrativeexample.json
is included./tests
: Houses test files, further categorized into:/unit
: Reflects the/src
structure, housing unit tests./integration
: Resonates with the/src
layout and contains integration tests.
/src
: The primary source folder, home to JavaScript files and a spectrum of subfolders encompassing distinct components:/assets
: Designated for assets, including SCSS and more./configurations
: Houses assorted settings like MongoDB, logger, and nodemailer./controllers
: Encompasses code pertinent to route handlers./middlewares
: Hosts middleware modules catering to application logic./models
: Encapsulates schemas and methods tailored for database models./routes
: Holds handler functions for diverse API endpoints./utilities
: Features utility functions and classes./validators
: Contains validation logic dedicated to user data./views
: Nurtures the creation of views and components via the Pug templating engine.
API Endpoints
Routes are created using Express.js
routes. Some of them are:
/api/
/api/about-us
/api/contact-us
/api/users/
/api/users/me
/api/users/:userId
/api/auth/login
/api/auth/logout
/api/reset-password
HTTP Verbs Used
- GET : Use this to fetch data from the DB to client
- POST: Use this when creating new record in DB
- PATCH: Use this when you partially update any entity
- DELETE: Use this when you are performing delete operation
HTTP Status Codes
Some of the status codes used are see all here in a file:
200
Used when youget data successfully
.201
Used when yourdata created successfully
.400
Used when there isbad request from the client
.401
Used when user isnot authenticated
.403
Used when user is authenticated but donot have permissions to access resource
.404
Used when datanot found
.422
Used whenpayload key(s) is valid
but the data in the key(s)are unprocessable
.500
is used forinternal server error
.
Contribution
Contributions are welcome! If you encounter issues or have improvements to suggest, please create a pull request.
Thank you for considering contributing to this project!
License
This project is licensed under the MIT License.