node js on mac machine

Update Node and npm on mac OSX

How to completely remove Node and reinstall it

It might be a bit annoying to uninstall stuff. But sometimes you gotta do it.

To uninstall node completely from your machine:
brew uninstall --ignore-dependencies npm

This will handle the issue you may have with dependencies. If you have other modules like yarn or jhipster on your machine, they are dependent on node and uninstalling might not come easy.

To uninstall node in a more aggressive way:
rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/npm*

how to install node, npm (node package manager) on Mac OSX

It is rather simple. Just go to https://nodejs.org and download and follow the steps.

How to dynamically construct Backbone js collection url

Constructing Dynamic URL in backboneJS Tutorial with Example

Working on Backbone js and wanted to pass the url dynamically?

Say you want to fetch the data based on the url


url: someurl/{dynamic-value}/content/{dynamic-value}

Here are some steps to accomplish constructing backboneJS url dynamically based on runtime values.

How to select element with multiple class

Solution

Lets assume your collection looks like this


var Members=Backbone.Collection.extend({
	url: function(){
		return url+'attendees/'+this.options.group;
	},
	initialize: function(models, options){
		this.options=options;
	}
});

On the above example your dynamic url might look like
http://somethingsomething.com/attendees/presenters – where presenters is something you added dynamically

and on your view


var Attendees=Backbone.View.extend({
	el: 'YOUR VIEW',
	render: function(){
		var view=this;
		var member=new Members([], {group: 'presenters'});
		member.fetch({
			success: function(members){
				var template= ...YOUR STUFF GOES HERE
		});
	},
	events: {
		'click #activities': 'membersByActivity'
	},
	membersByActivity: function(){
                YOUR LOGIC..
		return false;
	}
});

The important part for creating dynamic url in backbone js is:


var member=new Members([], {group: 'presenters'});

where you can change the presenters part as you like dynamically

node js server downloads text/html as file on browser

Those of you who work with webserver, like apache, might already have seen that problem – like the php file that was intended to display content would be downloaded as file.. this has some fix on configuration right..
Now coming to node js, once you install the server like

  1 var http_server=require("http");
  2 http_server.createServer(function(request, response){
  3     response.writeHead(200, {'Content-Type': "text/html"});
  4     response.write("I am listening @port 8896");
  5     response.end();
  6 }).listen(8896);

This should run fine once you run node filename.js where filename.js is the file containing the above code.
but, when you try to run by going to localhost:8896 and in place of seeing the text on your browser, if the browser decided to download the file, give a a careful look at line number 3 to be sure that you have specified correct content type..