Skip to content

Commit 446622a

Browse files
Complete code
0 parents  commit 446622a

19 files changed

+5626
-0
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.eslintrc.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"commonjs": true,
5+
"es2021": true
6+
},
7+
"extends": ["eslint:recommended", "prettier", "plugin:node/recommended"],
8+
"parserOptions": {
9+
"ecmaVersion": "latest",
10+
"sourceType": "module"
11+
},
12+
"plugins": ["prettier"],
13+
"settings": {
14+
"node": {
15+
"tryExtensions": [".js", ".json", ".node"]
16+
}
17+
},
18+
"rules": {
19+
"prettier/prettier": "error",
20+
"no-unused-vars": "warn",
21+
"no-console": "off",
22+
"func-names": "off",
23+
"no-process-exit": "off",
24+
"class-methods-use-this": "off",
25+
"node/no-unsupported-features/es-syntax": ["error", { "ignores": ["modules"] }]
26+
}
27+
}

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Compiled Output
2+
/node_modules
3+
4+
# OS
5+
.DS_Store
6+
7+
# ENV
8+
.env*
9+
*.env
10+
11+
# IDE - VSCode
12+
.vscode/*
13+
!.vscode/settings.json
14+
!.vscode/tasks.json
15+
!.vscode/launch.json
16+
!.vscode/extensions.json

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.prettierrc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"arrowParens": "always",
3+
"bracketSpacing": true,
4+
"endOfLine": "lf",
5+
"htmlWhitespaceSensitivity": "css",
6+
"insertPragma": false,
7+
"jsxBracketSameLine": false,
8+
"jsxSingleQuote": false,
9+
"printWidth": 120,
10+
"proseWrap": "preserve",
11+
"quoteProps": "preserve",
12+
"requirePragma": false,
13+
"semi": true,
14+
"singleQuote": true,
15+
"tabWidth": 4,
16+
"trailingComma": "es5",
17+
"useTabs": false,
18+
"vueIndentScriptAndStyle": false
19+
}

README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<div id="top"></div>
2+
3+
<h1 align="center">Node.js Express REST API MySQL JS Example</h1>
4+
5+
<div align="center">
6+
<p align="center">
7+
This REST API example is a basic backend application to test basic API functions with MySQL database.
8+
</p>
9+
<a href="https://www.postman.com/workspace/node-js-express-mysql-rest-api-example/overview">View Postman Files</a>
10+
</div>
11+
12+
<!-- TABLE OF CONTENTS -->
13+
<details>
14+
<summary>Table of Contents</summary>
15+
<ol>
16+
<li>
17+
<a href="#about-the-application">About The Application</a>
18+
<ul>
19+
<li><a href="#built-with">Built With</a></li>
20+
</ul>
21+
</li>
22+
<li><a href="#how-to-install">How To Install</a></li>
23+
<li><a href="#available-scripts">Available Scripts</a></li>
24+
<li><a href="#postman">Postman</a></li>
25+
</ol>
26+
</details>
27+
28+
<!-- ABOUT THE APPLICATION -->
29+
30+
## About The Application
31+
32+
This REST API example is a basic backend application to test basic API functions with MySQL database.
33+
34+
It is built with Node.js and Express Framework with Javascript. In addition, the applications database is MySQL, with the use of mysql2 library.
35+
36+
In the applicaiton we can manage user data, such as create/edit/delete a user. In addition, we can get all the users in the database.
37+
38+
The point of this backend application is to test CRUD operations with MySQL database.
39+
40+
<p align="right">(<a href="#top">back to top</a>)</p>
41+
42+
### Built With
43+
44+
- [Node.js](https://nodejs.org/en/)
45+
- [Express](https://expressjs.com/)
46+
- [Cors](https://www.npmjs.com/package/cors)
47+
- [MySQL2](https://www.npmjs.com/package/mysql2)
48+
49+
<p align="right">(<a href="#top">back to top</a>)</p>
50+
51+
<!-- INSTALLATION INSTRUCTIONS -->
52+
53+
## How To Install
54+
55+
**Git clone**
56+
57+
```
58+
git clone https://github.com/almoggutin/Node-Express-REST-API-MySQL-JS-Example
59+
```
60+
61+
**Instructions**
62+
63+
- After cloning the the repository run `npm i` in order to install all the dependencies.
64+
- Create an env file in the root of the project named .env and fill in the follwing variables: PORT, DB_HOST, DB_PORT, DB_USERNAME, DB_USERNAME_PASSWORD, DB_NAME.
65+
- In the sql directory, there are sql files that you will need to execute in order to initialize the database.
66+
67+
<p align="right">(<a href="#top">back to top</a>)</p>
68+
69+
<!-- AVAILABLE SCRIPTS -->
70+
71+
## Available Scripts
72+
73+
In the project directory, you can run:
74+
75+
### `npm start`
76+
77+
Runs the app in the production mode.\
78+
However, this script is only meant to be run when deploying the application. The application is built, where you need to setup the env variables on the machine that you will be hosting it on or on a web hosting service, unlike in development mode.
79+
80+
### `npm run dev`
81+
82+
Runs the app in the development mode.\
83+
Open localhost on the port you decided on in the env variables to view it in the browser.
84+
85+
The API will reload if you make edits with the use of nodemon.
86+
87+
<p align="right">(<a href="#top">back to top</a>)</p>
88+
89+
<!-- POSTMAN -->
90+
91+
## Postman
92+
93+
If you would like to run the files locally on your machine in the postman desktop application, included in the repository, in the `postman` directory all the files so you can import them. In addition you will have to configure env variables in postman so that you will be able to test properly everything.
94+
95+
<div align="center">
96+
<img src="./assets/postman/postman-global-env-variables.png" alt="Postman global env variables."/>
97+
<img src="./assets/postman/postman-jobs-env-variables.png" alt="Postman admin env variables."/>
98+
</div>
99+
100+
<p align="right">(<a href="#top">back to top</a>)</p>
Loading
165 KB
Loading

config/default.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
PORT: process.env.PORT || 3000,
3+
DB_HOST: process.env.DB_HOST || '',
4+
DB_PORT: process.env.DB_PORT || '',
5+
DB_USERNAME: process.env.DB_USERNAME || '',
6+
DB_USERNAME_PASSWORD: process.env.DB_USERNAME_PASSWORD || '',
7+
DB_NAME: process.env.DB_NAME || '',
8+
};

0 commit comments

Comments
 (0)