-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from philtrep/mysql-example
Added mysql example
- Loading branch information
Showing
7 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
## Mysql Service | ||
|
||
### Setup | ||
|
||
Copy the index file in this folder to the project root: | ||
|
||
```bash | ||
cd <project_folder>/ | ||
|
||
cp nodock/_examples/mysql/index.js . | ||
cp nodock/_examples/mysql/package.json . | ||
``` | ||
|
||
### Usage | ||
|
||
```bash | ||
cd nodock/ | ||
|
||
docker-compose up -d mysql node nginx | ||
``` | ||
|
||
By going to `127.0.0.1` in your browser you should be seeing a message indicating that `node` has successfully connected to `mysql`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var express = require('express'); | ||
var app = express(); | ||
var mysql = require('mysql'); | ||
|
||
app.get('/', function(req, res) { | ||
var connection = mysql.createConnection({ | ||
host : 'mysql', | ||
user : 'default_user', | ||
password : 'secret' | ||
}); | ||
connection.connect(function(err) { | ||
if (err) { | ||
res.send('Could not connect to MySQL ' + err.stack); | ||
} else { | ||
res.send('Connected to MySQL - Thread ' + connection.threadId); | ||
} | ||
}); | ||
}); | ||
|
||
app.listen(8000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "example-mysql-node-docker", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"dependencies": { | ||
"express": "^4.14.0", | ||
"mysql": "^2.11.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters