Skip to content

Commit 2260372

Browse files
New API Version 2.0.0
- Add PM2 server dev and production - Add rest api design patterns - Fix user authentication and creation - Remove MongoDB Warning
1 parent 997e04e commit 2260372

File tree

19 files changed

+241
-249
lines changed

19 files changed

+241
-249
lines changed

Procfile

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,24 @@ The API provides HTTP methods via AJAX requests to collect, insert and update th
2020
## Routes
2121

2222
| URL | Collection | Method | Parameters | Response | Action |
23-
| ------ | ------ | ------ | ------ | ------ | ------ |
24-
| https://rest-api-node.herokuapp.com/list/projects | projects | get | Nothing | JSON with Array | Get a list of projects in the database |
25-
| https://rest-api-node.herokuapp.com/create/project | projects | post | JSON | JSON | Add JSON into the database |
26-
| https://rest-api-node.herokuapp.com/update/project/:id | projects | put | id, JSON | Update the document with sent JSON data |
27-
| https://rest-api-node.herokuapp.com/select/project/:id | projects | get | id | JSON | Return the document, related to the sent id |
28-
| https://rest-api-node.herokuapp.com/delete/project/:id | projects | delete | id | status 200 | Delete the document, related to the sent id |
29-
23+
| ------ | ------ | ------ | ------ | ------ | ------ |
24+
| https://rest-api-node.herokuapp.com/projects | projects | get | Nothing | JSON with Array | Get a list of projects in the database |
25+
| https://rest-api-node.herokuapp.com/projects/create | projects | post | JSON | JSON | Add JSON into the database |
26+
| https://rest-api-node.herokuapp.com/projects/update/:id | projects | put | id, JSON | Update the document with sent JSON data |
27+
| https://rest-api-node.herokuapp.com/projects/select/:id | projects | get | id | JSON | Return the document, related to the sent id |
28+
| https://rest-api-node.herokuapp.com/projects/delete/:id | projects | delete | id | status 200 | Delete the document, related to the sent id |
29+
| https://rest-api-node.herokuapp.com/users | users | get | Nothing | JSON with Array | Get a list of users in the database |
30+
| https://rest-api-node.herokuapp.com/users/create | users | post | JSON | JSON | Add JSON into the database |
31+
| https://rest-api-node.herokuapp.com/users/update/:id | users | put | id, JSON | Update the document with sent JSON data |
32+
| https://rest-api-node.herokuapp.com/users/select/:id | users | get | id | JSON | Return the document, related to the sent id |
33+
| https://rest-api-node.herokuapp.com/users/delete/:id | users | delete | id | status 200 | Delete the document, related to the sent id |
34+
3035
## Collections
3136

3237
#### Schema Project (projects)
3338

3439
| Name | Description | Type |
35-
| ------ | ------ | ------ |
40+
| ------ | ------ | ------ |
3641
| project | project name | String |
3742
| technologies | project technologies | String |
3843
| description | project description | String |
@@ -43,25 +48,35 @@ The API provides HTTP methods via AJAX requests to collect, insert and update th
4348
| project | project name | String |
4449
| status | project status (Development / Production) | String |
4550

51+
#### Schema User (users)
52+
53+
| Name | Description | Type |
54+
| ------ | ------ | ------ |
55+
| username | user name | String |
56+
| password | user password (hash) | String |
57+
| email | user mail | String |
58+
| photo | user photo | String |
59+
| nickname | user nickname | String |
60+
4661
## API
4762

4863
| Technology | Description | Link |
4964
| ------ | ------ | ------ |
5065
| Heroku | Cloud Platform | [heroku.com] |
5166
| Heroku mLab Dyno | MongoDB database server | [mlab.com] |
5267
| GitHub | Version Controlling | [github.com] |
53-
| Nodemon | server reload, automatically | [nodemon.com] |
68+
| PM2 | server reload, automatically | [pm2.com] |
5469

5570
## API Directories
5671

57-
- Routes ```./app/routes```
58-
- Models ```./app/models```
59-
- API ```./app/api```
72+
- Routes ```./src/routes```
73+
- Models ```./src/models```
74+
- Actions ```./src/actions```
6075
- Configurations of Express ```./config/express.js```
6176
- Database configurations ```./config/database.js```
6277
- Server configurations ```./server.js```
6378

64-
## Configuring the API locally
79+
## Configuring the API locally
6580

6681
- Download or clone the project access the project folder with the terminal and execute the CLI <code>npm install</code>.
6782
- Run the server <code>npm start</code> (Nodemon)
@@ -73,11 +88,11 @@ The API provides HTTP methods via AJAX requests to collect, insert and update th
7388
- Dependency body-parser - <a href="https://www.npmjs.com/package/body-parser">https://www.npmjs.com/package/body-parser</a>
7489
- Dependency cors - <a href="https://www.npmjs.com/package/cors">https://www.npmjs.com/package/cors</a>
7590
- Dependency express-load - <a href="https://www.npmjs.com/package/express-load">https://www.npmjs.com/package/express-load</a>
76-
- Dependency Nodemon - <a href="https://nodemon.io/">https://nodemon.io/</a>
91+
- Dependency Nodemon - <a href="https://nodemon.io/">https://nodemon.io/</a>
7792

7893
By: <a href="http://renanlopes.com">Renan Lopes</a>
7994

8095
[heroku.com]: <https://www.heroku.com>
8196
[mlab.com]: <https://mlab.com>
8297
[github.com]: <https://www.github.com>
83-
[nodemon.com]: <https://nodemon.io/>
98+
[pm2.com]: <http://pm2.keymetrics.io/>

app/api/user.js

Lines changed: 0 additions & 88 deletions
This file was deleted.

app/routes/auth.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

app/routes/project.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

app/routes/user.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

config/database.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
/**
22
* Configuração base de dados / Database Configuration
3-
*
3+
*
44
* Português / English
5-
*
5+
*
66
* Host: Heroku mLab
77
* Database Type: MongoDB
88
* Database Name: heroku_jwprwsr5
99
* User: renanlopes
1010
* Password: renanlopescoder
11-
*
11+
*
1212
* PT: Configuração de base de dados local
1313
* EN: Configuration of local database
1414
* mongoose.connect('mongodb://localhost/databaseName');
15-
*
15+
*
1616
*/
1717

1818
let mongoose = require('mongoose');
1919

2020
mongoose.Promise = global.Promise;
2121

22-
mongoose.connect('mongodb://renanlopes:renanlopescoder@ds145312.mlab.com:45312/heroku_jwprwsr5');
22+
mongoose.connect('mongodb://renanlopes:renanlopescoder@ds145312.mlab.com:45312/heroku_jwprwsr5', { useMongoClient: true });
2323

24-
/**
24+
/**
2525
* PT: Função para imprimir no console se a conxão com o banco foi efetuada
2626
* EN: Function to print in console if the database connection was a success
2727
*/
@@ -57,4 +57,4 @@
5757
console.log('conexão fechada pelo temino da aplicação');
5858
process.exit(0);
5959
});
60-
});
60+
});

config/express.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
var express = require('express');
2-
var bodyParser = require('body-parser');
3-
var app = express();
4-
app.use(bodyParser.json());
5-
var load = require('express-load');
6-
var cors = require('cors');
1+
const express = require('express');
2+
const bodyParser = require('body-parser');
3+
const load = require('express-load');
4+
const cors = require('cors');
5+
const server = express();
76

8-
app.use(cors({origin: '*'}));
7+
server.use(bodyParser.json());
8+
server.set('secret', 'opensecret');
9+
server.use(cors({ origin: '*' }));
910

10-
app.set('secret', 'opensecret');
11-
12-
load('app/models')
13-
.then('app/api')
14-
.then('app/routes/auth.js')
15-
.then('app/routes')
16-
.into(app);
17-
18-
module.exports = app;
11+
load('src/models')
12+
.then('src/actions')
13+
.then('src/routes/auth.js')
14+
.then('src/routes')
15+
.into(server);
1916

17+
module.exports = server;

package.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "rest_api_node",
3-
"version": "1.0.0",
3+
"version": "2.0.0",
44
"description": "NodeJS REST API is a open code NodeJS Back End API",
5-
"main": "server.js",
65
"scripts": {
7-
"start": "nodemon ./server"
6+
"dev": "pm2 start server.js --watch",
7+
"start": "node ./node_modules/.bin/pm2 start server.js"
88
},
99
"author": "Renan Lopes",
1010
"license": "MIT",
@@ -16,12 +16,10 @@
1616
"express-load": "^1.1.16",
1717
"jsonwebtoken": "^7.2.1",
1818
"mongoose": "^4.7.1",
19-
"nodemailer": "^4.2.0"
19+
"nodemailer": "^4.2.0",
20+
"pm2": "^2.9.3"
2021
},
2122
"engines": {
2223
"node": "7.10.1"
23-
},
24-
"devDependencies": {
25-
"nodemon": "^1.11.0"
2624
}
2725
}

server.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
var http = require('http');
2-
var server = require('./config/express');
1+
const http = require('http');
2+
const server = require('./config/express');
33
require('./config/database');
44

5-
var port = process.env.PORT || 3000;
5+
const PORT = process.env.PORT || 3000;
66

7-
server.listen(port, function(){
7+
server.listen(PORT, () => {
88
console.log('Servidor Iniciado');
9-
});
10-
9+
});

0 commit comments

Comments
 (0)