Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js, PHP, Javascript Confusion [duplicate]

I am totally lost of what Node.js is all about so here's my question:

Is node.js a new language which can replace PHP or it is a language which can/only compliment/supplement PHP and other web languages to perform complex task?

like image 590
Orvyl Avatar asked May 05 '13 12:05

Orvyl


People also ask

Is Nodejs replacing PHP?

Is node. js a new language which can replace PHP or it is a language which can/only compliment/supplement PHP and other web languages to perform complex task? Short answer: Yes. You can replace all server-side Php with server-side Javascript.

Is PHP more popular than node JS?

A recent survey revealed that PHP is used by 78.9% of all websites with a server-side programming language. On the other hand, Node. js is an open-source, cross-platform runtime environment that executes JavaScript code beyond the boundaries of a web browser.

Is PHP better than node JS?

When it comes to the execution speed of PHP vs Node. js, the second is faster. If speed is extremely important for your application, e.g. a browser-based multiplayer game or a chat application, Node. js can become a better choice than PHP.

Can you replace JavaScript with PHP?

Nope PHP cannot be fully replaced. Yes node js is better but in some cases PHP is still very helpful and better choice like making single forms and small projects.


2 Answers

Node.js is server side Javascript environment based on chrome V8 javascript engine. It enables you to write your server code in javascript, instead of choosing one of the "traditional" web languages such as PHP, c#, python, ruby, perl etc. Using node.js and database such as mongodb you could write your web application completely in javascript.

Here's example of the full stack for web development:

  • Backbone for client side, code that runs in the browser (chrome,firefox)
  • Express server side framework running on Node.js
  • Mongodb database for storing documents

Above mentioned technologies will enable you create your application writing only javascript code, from browser to server and finally to database, sort of one language to rule them :), no need for PHP unless you have legacy codebase .

like image 116
slobodan.blazeski Avatar answered Sep 20 '22 20:09

slobodan.blazeski


First you have to understand the difference between server-side and client-side code.

Server-side code runs on the server, and it can do stuff like reading a database, getting file contents from the server, send mails etc. Examples of server-side code are PHP, Node.js, ASP.

Client-side code runs in the users webbrowser. It is used to make webpages interactive. This is mainly written in JavaScript.

PHP and Node.js are both server-side programming languages (altough node is a framework, but lets not make this any more complicated). They can both do things like database processing, reading files. As far as I know, you can't use both PHP and Node.js at the same time, so they can't even work together (there is probably some way to achieve this)

So to wrap it up: Node.js and PHP are both server-side and they can do the same thing. Node.js can replace PHP and vice versa

like image 40
Dirk Avatar answered Sep 24 '22 20:09

Dirk