Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Node.js

Hey,

I want to build my new website in Node.js as im a front end developer and it would be easier.

What would I need to be able to do this? Would it just be standalone node.js on a server or anything needed for it to run?

Is there going to be any treehouse tutorials on how to install and use it?

This video kinda puts me off Node.js is it true that Node.js is a crappy lanaguage which can't scale is not lightweight and is slow?

http://www.youtube.com/watch?v=1e1zzna-dNw

Thanks Brad :)

3 Answers

Patrick Cooney
Patrick Cooney
12,216 Points

If you're a front-end person and don't really want to deal with all the technical details of setting up a server you may want to use Heroku or for $5 a month you can get a digital ocean VPS and follow this tutorial.

As far as Node.js goes, I haven't done any real work with it. I went through a couple of tutorials. From what I can gather it's good for small things like building a lightweight chat client or something along those lines. If you just want a simple back-end I wouldn't imagine you'd have much trouble. If you wanted to build an advanced back-end with messaging (that persists) and/or file uploads you may want to consider something else.

Hayden Taylor
Hayden Taylor
5,076 Points

Node.js is powerful, fast and a lightweight language. It does offer a nice appeal to current front end users because its syntax is javascript. But it really depends what you want to do with it. You just want to learn it go ahead. Node.js isn't well suited for large computations, large action requests and is meant to have an big action loop so that is saves processing requests. A good example of the perfect use of node.js is a online chat platform such as irc.

You would need to download node.js and do the setup to run locally or purchase hosting which offers node.js.... I was looking at digitalocean myself for running rails but I saw they support node.js

I can't speak for treehouse about adding tutorials for it.

Jim Hill
Jim Hill
1,758 Points

Firstly take a look at platforms like nodejitsu that are designed for getting up and running with node.js without have to build the hosting environment.

One of the major advantages of node.js over say ruby is the fact that node.js code by default is asynchronous and non-blocking. An example in the real world of blocking vs non-blocking would be:

Blocking

You walk into a fast food chain and ask the person behind the counter for a burger. They take your order, go off to the kitchen, make your burger and then bring it back to you, take the money and now you are done. When they are done they can take the next order from the next customer in the queue.

Non-blocking

You walk into the same fast food chain and ask the person behind the counter for a burger. That person hands the order to to someone in the kitchen who goes off to make the food. You wait at the counter for your burger to be made whilst the next person in the queue can place their order. When your food is ready it is brought to you.

As you can see you can process lots more concurrent requests using non-blocking and as Hayden Taylor said, this is perfect for real-time apps like online chat where IO (input/output) is really important. Especially as many of these use a web technology called web-sockets to keep open a permanent connection with the server.

A complexity of node.js is that by default it single threaded (more information here: http://stackoverflow.com/questions/17959663/why-is-node-js-single-threaded) which means it is harder to do some CPU intensive tasks directly, and can also crash if you have not written your code to be non-blocking properly, so you need to be able to handle bringing the node.js server back up if in production when this happens. Companies like nodejitsu take care of this for you.

As a closing note I would say that it really depends on your application. If you are building a more "static" traditional website then all languages are pretty good if used well. The easiest way to do it would be to use a framework that it is built for web development such as Laravel for PHP (my fav), RoR for ruby, Django for Python, Locomotive for node.js etc. They will help you build web routes (the URLs), access databases, make your templates, help you with caching, handle forms etc (the list goes on!).

One other thing which you may be kind of used to as a front-end developer if you work with libraries like Backbone.js or Angular.js is the concept of splitting up your code to cover particular aspects of your app. Most language web frameworks tend to be structured using MVC, so this is always good to understand.