How to ci/cd a nodejs and mysql api

im new to ci/cd.

I have made an API that uses nodejs and MySQL

My tests work but they return the following error

error:  Error: connect ECONNREFUSED 127.0.0.1:3306
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1159:16)
    at Protocol._enqueue (/drone/src/node_modules/mysql/lib/protocol/Protocol.js:144:48)
    at Protocol.handshake (/drone/src/node_modules/mysql/lib/protocol/Protocol.js:51:23)
    at PoolConnection.connect (/drone/src/node_modules/mysql/lib/Connection.js:116:18)
...
    --------------------

my .drone.yml is as follows

---
kind: pipeline
name: node-latest

steps:
- name: test
  image: node:latest
  commands:
  - npm install
  - npm test

---
kind: pipeline
name: node14

steps:
- name: test
  image: node:14
  commands:
  - npm install
  - npm test

...

I don’t know what to do. i made a dockerfile and docker-compose file that run fine on my personal machine

The reason you are getting an error is because your unit tests require a running mysql server to connect with, and there is no mysql server running inside your node:latest container at 127.0.0.1

If you would like to start mysql as part of your pipeline, you can spin up a mysql container using the services section of the yaml. See the following docs:
https://docs.drone.io/pipeline/docker/syntax/services/

And here is a fully functioning example that you can use for guidance:
https://docs.drone.io/pipeline/docker/examples/services/mysql/

Please note that you cannot connect to mysql using 127.0.0.1 because this is the address of your node:latest container. When using the services feature, you need to connect to the mysql instance using the hostname / service name. This is demonstrated in the above links I provided.

Thanks for your help but node wont connect to my db

---
kind: pipeline
name: node-latest

steps:
- name: db-setup
  image: mysql
  commands:
  - sleep 30
  - mysql -u root -h database --execute="SELECT VERSION();"

- name: test
  image: node:latest
  commands:
  - npm install
  - npm test
  env:
  - NODE_ENV=test
  - NODE_PORT=8080
  - NODE_HOST=localhost
  - NODE_DB_PORT=3306

services:
- name: database
  image: mysql
  ports:
  - 3306
  environment:
    MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
    MYSQL_DATABASE: helpya
...

Thanks for your help but node wont connect to my db

Please provide more details. Can you provide a sample of the code you are using to connect? What values are you using to connect? What is the exact error message you received?