Friday, 4 December 2020

Express, get data from POST in form and INSERT into DB

 HTML file contains the following form:

<form action="/insertHolding" method="POST">

    <label for="hodl">Hodl</label><br>

    <input type="text" id="hodl" name="hodl"><br>

    <input type="submit" value="Submit">

</form>

In order to get the POST action from clicking the Submit button of the form, you must have the following

code in the app.js file:

app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); app.post('/insertHolding', function (req,res) {     db.query("INSERT INTO posessions (coin,amount) VALUES ('BTC',?)",[req.body.hodl], function (err,result) {

There is no body property on a standard Node.JS HTTP request. That key is patched on by the

 bodyParser middleware. We must add the bodyParser middleware.

https://stackoverflow.com/questions/44554038/typeerror-cannot-read-property-of-undefined-expressjs-post We have also installed express module by connecting to the running node container (docker exec -ti node bash). npm install express --save insert also the dependency into package.json

Sunday, 22 November 2020

Database changes

 In order to add a new table by the "CREATE TABLE" in create.sql, you need to remove the existing data directory and create a new with the same name. To be sure, run docker-compose build too

Render HTML in NodeJS

https://vegibit.com/render-html-in-node-js/

MySQL Data Type DECIMAL issue:

DECIMAL(19,9) has 9 digits for the fractional part and 19-9 = 10 digits for integer part

Replaced REAL with DECIMAL because of small fractional digits (eg. 1201.2200000345)

Friday, 20 November 2020

Getting back to AWS and Docker

  1. Google "aws"
  2. My Account > AWS Management Console
  3. E-mail and $ password
  4. Select EC2 from services
  5. Instances > Instances

sudo service docker start

Project I tried was teams and I just ran
docker-compose up -d
Public IP: 13.59.176.184

Next step: check foods if suitable and functional or create new repository


Sunday, 3 May 2020

Node_modules and editing local files

In order to map the local host files to the container working directory, you need to have the node_modules directory locally. Otherwise, the modules "Cannot be found".


With your new package.json file, run npm install. If you are using npm version 5 or later, this will generate a package-lock.json file which will be copied to your Docker image.

Since "npm install" is not possible without installing nodejs (that's why I user docker!), you have to run npm install inside a container which maps the local files.(/home/ec2-user/teams/node:/hasapian)
This could be run by running docker-compose without a volume at first of by building a node image.

Then add the volume above in the docker-compose.yaml and you are good to go!

Module versions:
https://semver.npmjs.com/

Monday, 20 April 2020

Git

Check os version in Linux: cat /etc/os-release

Install git for Fedora: sudo yum install git

Logged in with Administrator user and generated git credentials stored in notepad.

The created repository "hasapian-foods" can be found in the link below:

https://us-east-2.console.aws.amazon.com/codesuite/codecommit/repositories?region=us-east-2

Created github repository as well:

https://github.com/hasapian/foods

"git add ." works
"git status" is really helpful

Sunday, 19 April 2020

Connected!







Authentication error:
ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client

Solved by adding

command: --default-authentication-plugin=mysql_native_password

in the docker-compose.yaml file (found in the docker hub mysql image Readme file). Idea for the solution provided by
















https://stackoverflow.com/questions/50093144/mysql-8-0-client-does-not-support-authentication-protocol-requested-by-server

We also had issue with nodejs running before mysql server being ready. Changed entrypoint in docker-compose to app.js which does not connect to db. Then run dbhandler.js like the first image.

depends_on does not soleve the above issue. Scripts need to be created like the links below:




from https://docs.docker.com/compose/compose-file/

Solutions in case we need it in the future:

https://docs.docker.com/compose/startup-order/
Search for "No connections until MySQL init completes" in https://hub.docker.com/_/mysql
2 links are provided at the end.




Package json dependencies

To specify the packages your project depends on, you must list them as "dependencies" or "devDependencies" in your package’s package.json file. When you (or another user) run npm install, npm will download dependencies and devDependencies that are listed in package.json that meet the semantic version requirements listed for each


Friday, 17 April 2020