0

I have made a bot called "Hello Bot" but I want to have a database connection so I can do more things but I can not find a way to do it on will you help me?

1
  • I personally use mLab to host my database. It's free and pretty easy to learn to use
    – T. Dirks
    Nov 28, 2018 at 16:00

2 Answers 2

2

You can use something like SQLite or Enmap depending on what you're trying to do. You could also link into MySQL by running npm install mysql in your bot's directory and adding the following code at the top of your bot's js file:

const mysql = require('mysql');
const connection = mysql.createConnection({
  host     : 'hostname',
  port     : 'portnum',
  user     : 'db_user',
  password : 'db_user_password',
  database : 'db_name',
  charset : 'utf8mb4'
});

Note that you will have to install and setup MySQL on your server and create your database.

Here are a couple more links regarding setting my Node.js with Database access: https://hackernoon.com/setting-up-node-js-with-a-database-part-1-3f2461bdd77f https://tr-center.com/line/discord-js-bot-tutorial-part-6-xp-system-with-mysql-E5TVwyiCuYA.html

0

I'm a little late to the game on this one. But what I did with mine is used a atlas mongodb. I have my bot hosted on Amazon's AWS so connecting to a cloud DB was pretty easy from a nodejs project.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.