This is an article where the main subject is actually about how to connet to MySQL Database from a web-based application which runs in NodeJS. The main base of the web-based application project will use the one generated in the article titled ‘How to Create an Express Web-based Framework Application to be deployed in Node.js’ in this link.
So, the following is steps taken in order for the application can connect to MySQL Database.
This is an article where the main content is about how to install Express MyConnection package or module. It is a package or module which is added for special reason. The main reason is for the express framework powering a web-based application have the ability to connect to MySQL Database. Based on the description given in this link where the actual blog of the person created it. Based on the explanation on the person created which is written on the blog of the person himself, he mentioned that he had alreadly created the super simple middleware module express-myconnection that provides a consistent API for MySQL connections during the request/response life cycle. It is also stated that it supports three different strategies of managing db connections:
single for a singleton connection on an app instance level,
pool based connections, and a new connection per each
request. Another feature described is that it is also capable of auto releasing/closing connections if configured with either the
request strategy. But aside of that, the installation process itself is actually quite simple when it is actually involving npm tool. The process taken is shown as follows :
This article is an article where the title itself is quite a long title. But the main subject is focusing on how to install MySQL Database package or module. The package or module itself is used by the web-based application powered by the express framework. It can be referred from the article titled ‘How to Create an Express Web-based Framework Application to be deployed in Node.js’ in this link. So, the following are steps taken in order for the MySQL Database package or module to be installed in the web-based application :
The main goal is stated in the title of the article. It is done after creating a web-based application using express framework as shown in the article titled ‘How to Check to Package Dependencies in Web-based Application powered by Express Framework using npm’ in this link. The folder which contains files needed for a simple default page can be presented or can be displayed in a web browser is already created. So, the remaining things to be done is adding line for the app can be presented or can be displayed in a web browser. The steps taken to accomplish the task is shown as follows :
1. Add the following line into the file named app.js :
The line of script means that the application executed will start listen in port 3000. So, if there is any request further directed to that port, the application will serve and response the request.
2. Just start the application by using the command tool ‘node’. Below is the actual pattern of the command tool execution :
user@hostname:~/nodejs/test$ node app.js
GET / 200 676ms - 170b
GET /stylesheets/style.css 200 17ms - 110b
So, by executing the above command, node is actually serving itself to listen in to the port specified in the app.js file which is in the port 3000. So, every request send directly to port 3000 will be served by node and the response will be given back. The following is the output of the request made in the web browser :
How to Display Simple Default Page of a Web Page powered by Express Framework in Node.js
As shown in the above output, there is something printed in the page which is indicating the web-page powered by Express framework.