Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Node.JS Recreating My Arcade Bot In JavaScript And Would Like Some Assistance In It's Development.

Hello I am currently recreating my arcade bot that was in C# into node.js, and i'd like some help with it. I recently posted on it's C# thread that i'd like help with its main features including the database. If you have any experience with databases and node.js, and would like to help me out then don't hesitate to contact me via discord. Thanks in advance.
 
Do you have any particular question?
If so, it might be better to ask that here instead of using Discord, so that people who have the same problem(s) can find a solution later.
 
Well, it's been a bit since I used Node.js, but I was learning it a few months ago when I made a task management app (Taski) with Electron.
You are first going to need to make sure you have MySQL installed with npm (npm install mysql).

In one of your main server files for Node, you will need to use...
var yourVariableName= require('mysql');

This makes sure MySQL is included.
Obviously you could use something else to power your database, but MySQL is the most common & easiest solution.

JavaScript:
var db = mysql.createConnection({
  host: "localhost", // Change if you are connecting to another server
  database: "DATABASE-NAME-HERE",
  user: "USERNAME-HERE",
  password: "PASSWORD-HERE"
});

db.connect(function(error) {
  if (error) throw error;
  console.log("Server is connected to the database!");
});

This will create a DB variable that is connected to your MySQL database with your credentials.

Or, you could do something like this to actually query the database!
JavaScript:
db.connect(function(error) {
  if (error) throw error;
  console.log("Server is successfully connected to the database!");
  db.query("SELECT game_title FROM arcade_games WHERE game_id = 5", function (sqlerror, sqlresult) {
    if (sqlerror) throw sqlerror;
    console.log(sqlresult);
  });
});

I highly recommend setting up separate functions to handle DB connecting & DB querying.
You will obviously need to do a bit more research on how to effectively validate/sanitize user data with Node / JavaScript, but connecting to a database is easy. It's literally just ...
DBCONNECTIONVARIABLE.query(queryGoesHere, function(errorVariable, resultVariable){ // stuff });

So, once your protected db variable is created you can easily connect.
Or you can open & close your connection as needed, with a simple function to reconnect to the database & initialize the dbconnectionvariable when its required. Then just run your query. That way you can manage your DB connecting in one place instead of across many files. :)
 
There's no question in this thread, just a thread i posted seeking help(devs) to help me develop my bot.
Please make ensure that you uncheck the 'Questions' option before creating a post if you are not asking a question. I have edited the thread and removed the question status. :)
 
Please make ensure that you uncheck the 'Questions' option before creating a post if you are not asking a question. I have edited the thread and removed the question status. :)
Yeah, I would love to know if my instructions for connecting to a database & running a basic query were helpful :)
 
Well, it's been a bit since I used Node.js, but I was learning it a few months ago when I made a task management app (Taski) with Electron.
You are first going to need to make sure you have MySQL installed with npm (npm install mysql).

In one of your main server files for Node, you will need to use...
var yourVariableName= require('mysql');

This makes sure MySQL is included.
Obviously you could use something else to power your database, but MySQL is the most common & easiest solution.

JavaScript:
var db = mysql.createConnection({
  host: "localhost", // Change if you are connecting to another server
  database: "DATABASE-NAME-HERE",
  user: "USERNAME-HERE",
  password: "PASSWORD-HERE"
});

db.connect(function(error) {
  if (error) throw error;
  console.log("Server is connected to the database!");
});

This will create a DB variable that is connected to your MySQL database with your credentials.

Or, you could do something like this to actually query the database!
JavaScript:
db.connect(function(error) {
  if (error) throw error;
  console.log("Server is successfully connected to the database!");
  db.query("SELECT game_title FROM arcade_games WHERE game_id = 5", function (sqlerror, sqlresult) {
    if (sqlerror) throw sqlerror;
    console.log(sqlresult);
  });
});

I highly recommend setting up separate functions to handle DB connecting & DB querying.
You will obviously need to do a bit more research on how to effectively validate/sanitize user data with Node / JavaScript, but connecting to a database is easy. It's literally just ...
DBCONNECTIONVARIABLE.query(queryGoesHere, function(errorVariable, resultVariable){ // stuff });

So, once your protected db variable is created you can easily connect.
Or you can open & close your connection as needed, with a simple function to reconnect to the database & initialize the dbconnectionvariable when its required. Then just run your query. That way you can manage your DB connecting in one place instead of across many files. :)
Thank you, I will look into this and see what I can do.
 
Thank you, I will look into this and see what I can do.
Yeah, of course!
If you can share some of your code I can definitely help you out a bit more, but it's hard to come up with a good "answer" in this thread because your thread is quite broad. If you can update your thread with some specific questions or segments of code, it will be a lot easier for us to help you! We are trying to avoid broad or extremely large topics in these programming sections. For example, you could make a thread "How do I convert database connection from PHP to Node.js?" and receive some quick answers that not only help you, but also help other users now and in the future. Then you could create a thread along the lines of "How to query database for game information list in Node.js?", which would allow us to show you how to query a database for a list of results & then use them on your web page. Specific questions yield better answers, I promise! :)
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom