3

Why I'm looking at node.js

I have a low-traffic site with .html, .css, and .js files. For the purposes of this post, a good analogy is a high school course website for learning javascript. I need to add a tiny bit of backend. I need
1) A small db to store users and their "grades." I've used php+mysql on apache for something like this in the past
2) An ability to evaluate user-submitted javascript server-side and grade the result. Node.js has vm and sandbox, so I figure I should turn to node.js (if you have an alternative approach let me know!).

My issue

I've never used node.js before, and I'm a bit confused by the tutorials out there and how they fit into the "old fashioned" web development context. The hello world tutorials start with making a server. For the purposes of having a tiny backend, that sounded like overkill, until I read this, which explained things a little better, saying that (in simplified terms) node.js replaces apache and has added benefits, etc.

In order to have the capabilities of the tiny backend I list above, is a full node.js app necessary? At this point I don't need persistent I/O. I only need the server-side javascript evaluation. Is there a way to have an "old-fashioned server" serve my html with a php backend for a database (bullet 1 above), but then add a small node.js app evaluating the user-submitted javascript (bullet 2 above)? I'm concerned that if, as a beginner, I run an http server in node.js I would be opening security holes that other super-mature web servers smoothly deal with behind the scenes. Also, if I get a hosting plan with nodejitsu/heroku/etc, do they not serve .html automatically? You have to start from scratch with a server?

Community
  • 1
  • 1

1 Answers1

1

First , Its not a bad idea to use node.Js to satisfy your requirement,the uniqueness of NODE and added advantage compared to conventional technologies like Apache-PHP is clearly explained in this following video Why Node.JS is better.The notion of NODE being just used for advanced or complex applications is wrong , you can use node for building applications which are very simple to anything of huge proportion.It would be a not so comfortable task for a node beginner to code without using any frameworks , but by using this web application framework called express , you need not code from scratch and its very easy to setup html pages using its simplified html templating language called JADE and route requests,also you can even use your html pages if you are not willing to use JADE for rendering the views of your application .Here are the series of tutorials which would help you Tutorials on beginning with node.js , Basics of expressJS , Advanced express tutorials. The series of videos also have tutorials on getting connected to the no-SQL database MONGO-DB , Mongo is most popular database that is used alongside NODE backend , here is the video which compares mongo and SQL Mongo V/s SQL. Using Node would also enhance the scalability of your web application , which is very important for any web based services . Node is not meant to be used alongSide PHP , those are completly two different backend technologies , why would you want to use PHP-Apache and node together when you can very easily build the application using express framework , i suggest go ahead with NODE-Express-Mongo .

Karthic Rao
  • 3,624
  • 8
  • 30
  • 44