I'm really new to node.js and MySQL, and when I try to learn both at once... let's just say I need some help. ;)
I want to use the node-mysql module to dynamically edit a database via node.js. All the basic code is in place.
var http = require('http'),
mysql = require("mysql");
var connection = mysql.createConnection({
user: "root",
password: "",
database: "ballot"
});
http.createServer(function (request, response) {
request.on('end', function () {
connection.query('SELECT * FROM data;', function (error, rows, fields) {
response.writeHead(200, {
"Content-Type": "text/plain",
'Access-Control-Allow-Origin' : '*'
});
response.write(JSON.stringify(rows));
response.end();
});
});
}).listen(8080);
The problem is, I'm listening on port 8080, and localhost is of course port 80. Should I listen on port 80? If so, how do I do so without messing with Wamp? And how can I access the databases I create with PHPmyAdmin?
WAMP gives you a number of things, including MySQL and an apache web server with phpMyAdmin pre-configured.
By default the Apache web server listens on port 80 and the MySQL server listens on port 3306. With WAMP running, these ports will be taken. Your node process will be able to create a server listening on port 8080 as long as you have no other processes listening on port 8080. By default this should be fine and you will be able to access the node http server via http://localhost:8080
A connection with the MySQL database is established on port 3306. You just need to setup your database as you normally would through phpMyAdmin. By default this will be at http://localhost/phpMyAdmin
which is running on the apache server on port 80.
Just to clarify, as your terminology seems slightly confused. Localhost in a host name. It's the location of the machine that you wish to talk with. The port number is completely separate and "localhost is of course port 80" doesn't make any sense. You can specify any valid port number for localhost. As I already mentioned, listening on port 8080 means you can access the node server through http://localhost:8080