Creating a simple web application with Node, Express and MySQL.
- MySQL server for data
- Node-Express Web-Server to create, update, read, and delete the data displayed on the UI as a table.
A simple usecase is to have external automation systems report new data to MySQL server. And see those data updates on the web UI. Great for those who are not required to spend much of their time building dedicated web server and ui.
-
You need to install docker on your host. See Install-Docker-on-Ubuntu.
-
Go to your terminal.
-
Clone this repository.
-
Update MySQL password to following two files
- For
testbed-mysql
MySQL container: ops/mysql/.credentials - For
testbed
Nodejs container: src/express_app/.env
NOTE: Defaults are already set in the file - USER: root DB: testdb
- For
-
Run following scripts to setup MySQL DB
-
Setup
testbed-mysql
MySQL container:./ops/mysql/run-mysql-server.sh
Or, if you want to remove all previous docker containers and images also, run this instead -
./ops/mysql/run-mysql-server.sh rmi
-
Setup
testbed
Nodejs container:./ops/node-express/run-node-express-server.sh
-
-
To exit from current container without closing it press following keys 1 or 2 times
ctrl + p + q
-
This application inside docker container page can be browsed at following URLs
SERVER SIDE
- server side json response @ http://CONTAINER-IP:12000/thor/api
- server side default error.ejs response @ http://CONTAINER-IP:12000/404
- server side index.ejs response @ http://CONTAINER-IP:12000/thor/ejs/index
- server side index.html response @ http://CONTAINER-IP:12000/thor/html/index
CLIENT SIDE
- client read-only datatables ui @ http://CONTAINER-IP:12000/datatables
- client editable footable ui @ http://CONTAINER-IP:12000/footable
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
baeace45220f testbed bridge local
...
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
475203aa27f7 mjaglan/expressnode "/bin/sh -c bash" 5 minutes ago Up 5 minutes 0.0.0.0:12000->3000/tcp testbed
146d749c1272 mysql:5.6 "docker-entrypoint.s…" 31 minutes ago Up 31 minutes 3306/tcp testbed-mysql
...
Project Structure (src/express_app)
├── .env
├── app.js
├── bin
│ └── www
├── config
│ └── log4js.json
├── package.json
├── public
│ ├── datatables (client pages)
│ ├── footable (client pages)
│ └── favicon.ico
├── routes
│ └── index.js
└── views
├── error.ejs
├── index.ejs
└── index.html
-
.env
file stores MySQL DB Credentials like this -DB_HOST=<mysql-host> DB_USER=<mysql-user> DB_PASS=<mysql-pwd>
-
app.js
file is the entry-point of your application (contains the express core, such as uri parser, modules, database) -
bin/
folder should contain the various configuration startup scripts for your application. -
package.json
file contains all of your dependencies and various details regarding your project (used by npm for dependencies and sharing). -
public/
folder contains all of your front-end code - client static files (CSS, client JavaScript, jQuery, images, fonts, etc.) -
routes/
folder contains all the routes that you have created for your application. Contains the main back-end code (server side), which compute data before calling a template engine (see below) or respond to the client (via json/ xml). -
views/
folder contains all of your server-side views. Contains each page template, see jade template. These files are used by scripts in "route".
Docker version 18.03.1-ce
Ubuntu 16.04.4 LTS Host OS
- Express.js Project Structure
- Creating a basic site with Node.js and Express
- Docker Official Image packaging for MySQL Community Server
- MySQL With Node & Express
- Render HTML file in ExpressJS
- Express Application Settings
- Setup pooled MySQL connections in Node JS that don’t disconnect
- mysqljs Pooling connections
- Node Logging Basics - log4js
- ReST API - CURD Operations using Node Express MySQL
- FooTable - create a table that uses the editing component
- Can't create symlinks in virtualbox shared folders - serverfault.com