NodeJs API, MySql

Sebastian Velez Zuluaga
2 min readJul 23, 2020
  1. Install mySql
  2. Creare the Env varible to use mySql from terminal, in te bash_profile file.
    export PATH=${PATH}/usr/local/mysql/bin/
  3. Install workbench or something like that to control the database, and open it .
  4. Create the schema and the tables that you need.

5. In out project install mySql module

npm install mysql

6. Create de code to access the DB and querys , with the schema of files that you wnat.

7. To access the Mysql 8.0 you have to change de permission for root user.

ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘password’

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

Help link: https://bezkoder.com/node-js-rest-api-express-mysql/

8. Update Code and run server — daemon.

npm install — save nodemon

Link: https://www.npmjs.com/package/nodemon

9. Create the script on package.json

“start”: “nodemon index.js”

10 Run on your terminal

npm start

11. Use enviroment variables, first create a .env file

12. Install the extension for VisualCode

npm install dotenv

13. You can install the extensin for VisualCod

14. Create a .env file with your keys and values

15. Creat a file config.js to access whole variables.

16. To run a specific script you have to type:

npm run “your script”

GitHub link : https://github.com/sebastianvz/Template-NodeJS-Api/tree/mySql

--

--