Skip to content

Commit cfe1727

Browse files
committed
Added mysql support
1 parent 7a44241 commit cfe1727

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# express-mongoose-es8-rest-api
22

33
## Description
4-
Nodejs boilerplate with express,Mongoose,ES8,Jwt to develop rest api
4+
Nodejs boilerplate with express,Mongoose,Mysql,ES8,Jwt to develop rest api
55

66
[![specification](https://img.shields.io/badge/ES8/ECMASCRIPT-2017-yellow.svg)](https://www.ecma-international.org/ecma-262/8.0/index.html)
77
![node version](https://img.shields.io/badge/node-%3E%3D%208.10.0-brightgreen.svg)
88
[![express](https://img.shields.io/badge/express-4.x-orange.svg)](https://github.com/expressjs/express)
99
[![mongoose](https://img.shields.io/badge/mongoose-5.4.12-red.svg)](https://mongoosejs.com/)
1010
[![jsonwebtoken](https://img.shields.io/badge/jsonwebtoken-8.4.0-green.svg)](https://github.com/auth0/node-jsonwebtoken)
11+
[![mysql](https://img.shields.io/badge/mysql-2.16-blue.svg)](https://github.com/mysqljs/mysql)
1112
[![code style](https://img.shields.io/badge/eslint--config--standard-%5E12.0.0-blue.svg)](https://github.com/standard/eslint-config-standard)
1213
![Dependencies](https://img.shields.io/badge/dependencies-up%20to%20date-brightgreen.svg)
1314

@@ -25,7 +26,7 @@ Nodejs boilerplate with express,Mongoose,ES8,Jwt to develop rest api
2526
- Manage enviroment via [dotenv](https://github.com/rolodato/dotenv-safe)
2627
- Code coverage with [istanbul](https://github.com/istanbuljs/nyc)
2728
- uses [helmet](https://github.com/helmetjs/helmet) to secure api endpoints which adds necessary security headers
28-
29+
- Added support for databases like [mysql](https://github.com/mysqljs/mysql) and [mongoDB](https://github.com/Automattic/mongoose) with async await
2930
## Getting Started
3031
1. Clone repository
3132
```

server/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const app = express()
1414

1515
app.use(bodyParser.json())
1616
app.use(helmet())
17-
app.use(jwt({ secret: secretCallback }).unless({ path: [ '/api/health-check', '/api/users', '/api/auth/login' ], requestProperty: 'auth' }))
17+
app.use(jwt({ secret: secretCallback }).unless({ path: [ '/api/health-check', '/api/users', '/api/auth/login', '/api/users/testmysqlroute' ], requestProperty: 'auth' }))
1818
app.use('/api', Router)
1919

2020
// Handle 404

server/modules/users/user.routes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ const userRoutes = express.Router()
99
userRoutes.get('/', asyncWrapper(users.index))
1010
userRoutes.post('/', validate(newuser), asyncWrapper(users.create))
1111
userRoutes.put('/:id', asyncWrapper(users.update))
12+
userRoutes.get('/testmysqlroute', asyncWrapper(users.testMysql))
1213

1314
export { userRoutes }

server/modules/users/users.controller.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { userModel } from './user.model'
22
import { httpStatus } from '../../utils/httpStatus'
3+
import { pool } from '../../config/mysqlconnect'
34
const users = {}
45

56
users.index = async (req, res) => {
@@ -21,4 +22,8 @@ users.update = async (req, res) => {
2122
return res.json({ message: 'Record updated' })
2223
}
2324

25+
users.testMysql = async (req, res) => {
26+
let data = await pool.query('Select * from users')
27+
return res.json({ data })
28+
}
2429
export { users }

0 commit comments

Comments
 (0)