0

I always considered javascript as client side script with no possibilites working with server side but due to node.js it has changed. But I still don't understand how it could work, e.g. look at this code :

var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'dbuser',
  password : 's3kreee7'
});

connection.connect();

connection.query('SELECT 1 + 1 AS solution', function(err, rows, fields) {
  if (err) throw err;
  console.log('The solution is: ', rows[0].solution);
});

connection.end();

javascript is displaying on client side, so everyone can see login and password to DB? Or in node code isn't displaying on client side ?

So in case if smne have phpmyadmin directly on his server like website/phpmyadmin or website/mysql it allows hackers login to it ? Sorry if it's dumb question, I never worked with node before.

1
  • make sure to not serve your nodejs files (eg. putting it somewere inside the DocumentRoot), else everyone will see your password Commented Mar 15, 2016 at 12:33

2 Answers 2

1

this code is being executed on server side,

we can say that this code is similar to php, just on PHP.

Nobody can access(normally) server side code.

Sign up to request clarification or add additional context in comments.

Comments

0

Node.js allow to run Javascript out of browser, in backend, similar PHP like say @alexey, but in order to run the JavaScript you intend to run on the backend, it needs to be interpreted and executed. This is what Node.js does, using the Virtual Machine V8 Google, the same JavaScript runtime environment used by Google Chrome.

The main particular it is as an asynchronous event driven framework.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.