1

Recently I started playing with node.js.

Since I'm developing a web app, I was interested in the benefits of google's javascript V8 engine, i started reading stuff about all this - and node.js.

An example of a webapp which uses node.js: http://bodesigns.com/simple-web-app-using-node-js/

As you can see, it uses node.js to connect to a mysql database. Some questions about this: - First of all, is this safe? I mean: the username and password are stored in the file. I know, in PHP it is to, but a PHP-file is server-side. Node.js is server-side?

  • Second, with this (i'm also building a part of the web app with google maps stuff), i could replace the PHP-code I have now to collect some data from a mysql database? What are the (dis)advantages of replacing the PHP-code with node.js code?

  • Last: can I run a node.js server asynchronously? I mean: i have a HTML-page with a link (). When i click it, it must "run" the node.js-script, which collects data form the mysql-database. Like in the example. So when the page loads, only an empty map has to be visible. If you click something, markers have to show or hide. Is this possible?

  • My apologies for my bad English.

1 Answer 1

3

First of all, is this save?

node.js runs on the server, the code doesn't need to go to the client so it's safe.

What are the (dis)advantages of replacing the PHP-code with node.js code?

Do you need to rewrite code that already works? If your writing new code then PHP vs node.js is a completely different and application specific discussion. For generic applications they are both suitable

Is this possible?

Yes, however it's also possible with PHP.

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

5 Comments

Last question: how is it possible to run PHP-code asynchronously? Or do you mean AJAX?
@v3rt1g0 I meant ajax. But you can also run PHP asynchronously if you link a non blocking IO library
I think you are mixing up asynchronous AJAX requests with the event based asynchronous processing NodeJS does. The client making an AJAX request doesn't care how the server produces the result. @Raynos Is there something usable like Twisted or EventMachine for PHP?
@Daff there should be something like node/twisted/eventmachine for PHP. However note that most web servers run PHP as CGI scripts with a one process per request model. You can't use PHP on a CGI based server and use something like twisted/eventmachine. You would basically have to write the web server in php.
Yeah that was what i was wondering. Doesn't sound like a trivial thing to do in PHP.

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.