William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

Tag Archives: Node.js Express

NodeJS CompoundJS and Rails

NodeJS CompoundJS and Rails

CompoundJS is a NodeJS MVC framework, it can be acquired from
CompoundJS’s github.
It is easy to use and grasp, with high performance. By using it with MongoDB (with jugglingdb to access), pretty good feeling.
I am quite impressive with its succinct, smart, well-designed structure: Routing, Controllers and EJS-style Views.

The following is a quick-start:

# install compoundJS globally:
$ sudo npm install compound -g

# initialize app
$ cd ~
$ compound init blog && cd blog
$ npm install

# generate scaffold
$ compound generate crud post title content published:boolean

# run server on port 3000
$ compound s 3000

# visit app
$ open http://localhost:3000/posts	

Rails is also good for Agile development,
, Gemfile = package.json

rails with mongo_mapper(MongoDB accessor) support.

 $ rails generate scaffold tpouser user:string --skip-migration --orm mongo_mapper
 $ rails generate model Info  first_name:string last_name:string phone:string e_mail:string --skip-migration --orm mongo_mapper
 $ rails generate model Count contacts:Integer prospects:Integer closings:Integer listings:Integer --skip-migration --orm mongo_mapper	

NodeJS episode series

NodeJS & Express: Upload Images

NodeJS & Express: Upload Images

There is an excellent article showing to use Node.js and Express to upload file/image. For the upload form:

<form id="uploadForm"
 <input type="file" id="userPhotoInput" name="userPhoto" />

It uses setInterval call function, that is continually checking the value of the input element, once it has a value it can assume the user has selected a file and it will kick off the upload.

 var timerId;
   timerId = setInterval(function() {
   if($('#userPhotoInput').val() !== '') {
 }, 500);

I can list many reasons that setInterval here is not a suitable solution. For general usage, I change it to onChange event:

$('#userPhotoInput').change(function(e) {
   //nothing to do if the upload field is null
   if($(this).val()=='' || /^\s+$/.test($(this).val()) return false;
   else $('#uploadForm').submit();
   return false;

This way seems much better: when upload field changes, the changed file/image immediately uploaded, if null, nothing to upload.