corazza
corazza

Reputation: 32354

Can Node.js have the same functionality as PHP, or should they be used together?

I know the basics of both PHP and Node.js, but I don't understand why some people argue over which one is better... Can Node.js be used to render web pages like PHP can? For example, can you make a BBS using Node.js (I know you have access to DBs, but rwndering posts seems to be a problem)? It seems to me like Node.js can be used either as a very simple HTTP server, that only serves basic HTML, without changing it, or for communication (which I use it for). For example, I'm making a browser MMO game, and I use PHP to serve the site and the forum/devblog, and Node.js for the actual game. Or am I missing something?

Upvotes: 2

Views: 1074

Answers (2)

Tadeck
Tadeck

Reputation: 137350

Can Node.js be used to render web pages like PHP can?

Yes. There are some differences, but the main idea is to use Node.js on the server-side to serve responses to the requests, similarly to PHP. So again, yes, you can render web pages using Node.js.

Can you make a Bulletin Board System using Node.js?

Yes. Rendering posts also can be done within Node.js. You can render posts also on client side JavaScript, so why you think server-side JavaScript (Node.js) would be more limited? For templating see eg. {{ moustache }} or Pure.

The main advantage of Node.js over "standard" PHP is that JavaScript is event-driven and you use single thread for all the requests, whereas in PHP you use separate thread for every request.

Node.js lets you write your own "server" using only JavaScript. It simplifies a lot if you want to build eg. communication server.

More resources

For more comprehensive solution for rendering web pages in Node.js see eg. ExpressJS Node.js framework. You may specifically be interested in the way ExpressJS allows you to render views.

Upvotes: 8

Nicola Peluchetti
Nicola Peluchetti

Reputation: 76880

Someone will give a more detailed answer than me but basically node.js can replace both Apache and Php. It's a platform that allows you to create a web application using only javascript. It has a different model respect to apache because node is event driven (being written in javascript) while Apache uses threads.

Anyway take a look here for a decent tutorial on node, the best way to understand it's by using it i think

Upvotes: 1

Related Questions