Simple Local Server Tip

I generally use https://www.npmjs.com/package/http-server to run my local web server. http-server works really great, however lately I've been finding myself using SimpleHTTPServer because it's already installed on my Mac and it's, well... simple (obviously, given the name).

Try it:

Open terminal.app and run
cd ~/Sites/some-project (or wherever your static project files exist)

and now fire it up:
python -m SimpleHTTPServer 8000 (or choose another port number)

then simply visit http://localhost:8000 :)

Happy coding!

I generally use https://www.npmjs.com/package/http-server to run my local web server. http-server works really great, however lately I've been finding myself using SimpleHTTPServer because it's already installed on my Mac and it's, well... simple (obviously, given the name). Try it: Open terminal.app and run cd…

Read More

Launching Soundfly.com with NodeJS

For the past month or so, I've been working on creating an interactive music learning platform with a bunch of amazing and talented musicians, DIYers and makers in Brooklyn called Soundfly.

We're launching our initial concept on September 3rd, 2014 and we're excited to see how the app translates to the rest of the world. Particularly those interested in learning how to play music for the first time as well as advanced courses that will teach you a thing or two about how to improve your current playing skills.

My role at Soundfly is CTO, which is fitting since I am the only tech person (this startup is running lean and I love it) for now. Prior to joining I started working on porting all of my existing PHP apps and websites over to NodeJS, Express, MongoDB, Jade, and Less. I couldn't be any happier with this decision and I've been writing Soundfly's new codebase using a boilerplate NodeJS app that I created prior to joining the team. It's not only helped us produce more work in roughly one month's time, it's also allowed me, a single developer, to rapidly prototype Ian's (our CEO/Founder) design and product decisions in a more flexible and time saving approach.

I honestly love working in Javascript, I never thought I would be using it for an entire web stack. I mean, working in Atom (Githubs IDE) which is written in NodeJS, the ease of installing modules through NPM, the ability to debug so much easier, and working with JSON through the app is incredibly fun to me.

For us at Soundfly, we plan on thinking big and acting small. With that said, we need to move quickly and a have laser sharp understanding and focus of our individual contributions in order to be the most effective and productive. I'm afraid of how long this project would have taken me if I created it in another language. Node is becoming my all time favorite and it's making my job fun and full of life again.

After our launch in September, we will be focusing on several new courses and more advanced interactive learning games. We've been asking the question of "how do people learn online?" we don't believe it's a one size fits all model, we believe people take different steps in learning and comprehension and that everyone's path is unique. We're planning on discovering some best practices and applying these concepts on an more individual and impactful level. Indeed, we have some wonderful challenges ahead and I'm really looking forward to seeing how our app performs throughout it's lifespan.

If you're reading this and thinking to yourself that you would like to start learning how to play music from anywhere, please visit http://soundfly.com and signup to be notified of our official launch.

For the past month or so, I've been working on creating an interactive music learning platform with a bunch of amazing and talented musicians, DIYers and makers in Brooklyn called Soundfly. We're launching our initial concept on September 3rd, 2014 and we're excited to see how the app translates to…

Read More

Mongoose Populate

I found this to be extremely helpful recently when dealing with MongoDB NodeJS joins. Pay close attention to this = "stories : [{ type: Schema.Types.ObjectId, ref: 'Story' }]"

var mongoose = require('mongoose')  
  , Schema = mongoose.Schema

var personSchema = Schema({  
  _id     : Number,
  name    : String,
  age     : Number,
  stories : [{ type: Schema.Types.ObjectId, ref: 'Story' }]
});

var storySchema = Schema({  
  _creator : { type: Number, ref: 'Person' },
  title    : String,
  fans     : [{ type: Number, ref: 'Person' }]
});

var Story  = mongoose.model('Story', storySchema);  
var Person = mongoose.model('Person', personSchema);  

then use .populate() to grab the story's ref

Story  
.findOne({ title: 'Once upon a timex.' })
.populate('_creator')
.exec(function (err, story) {
  if (err) return handleError(err);
  console.log('The creator is %s', story._creator.name);
  // prints "The creator is Aaron"
})

I found this to be extremely helpful recently when dealing with MongoDB NodeJS joins. Pay close attention to this = "stories : [{ type: Schema.Types.ObjectId, ref: 'Story' }]" var mongoose = require('mongoose') , Schema = mongoose.Schema var personSchema = Schema({ _id : Number, name : String, age : Number, stories : [{ type: Schema.Types.ObjectId, ref: 'Story' }] }); var…

Read More

Express 4 in production

Express 4 just got released thanks to the great work of @defunctzombie and the expressjs team.

The main change is, that Express does not have connect as a dependency anymore, which means that the bundled middlewares are no longer available in the express module. These should be installed and listed in your apps package.json. This allows faster updates of the middlewares without affecting the release cycles of express.

Migrating

The things you should pay attention to:

  • app.configure(): removed, no longer available
  • app.router: removed, no need to manually do it
  • express.createServer(): removed, use express()
  • public API for the Router

It took only a day to change to new version of express, in a medium size application like ours.

For more, please check the migrating guidelines and the list of new features.

In production

We have deployed to only one API node for testing purposes (after running it several days on our staging environment) just to see how it performs under heavy load. We are serving millions of requests every day so even in this setup the node with the new version still receives lots of requests.

In short: hats off! All of our metrics improved on the API node using the new version of Express:

  • response times dropped by 20%
  • memory consumption dropped by 10%

Conclusion

As you can see, the effort you have to put in to migrate the new version is very little compared to the performance gains. If you have at least integration tests to check if everything is okay, you should definitely start using the new version.

Express 4 just got released thanks to the great work of @defunctzombie and the expressjs team.The main change is, that Express does not have connect as a dependency anymore, which means that the bundled middlewares are no longer available in the express module. These should be installed and listed…

Read More

Nodejitsu Rocks

Deploying NodeJS apps has been painful in my past. I have used Heroku in the past, but I think I found my new love...Nodejitsu. You can see my latest open source project "Kano" by pointing your browser towards http://kano.jit.su.

Deploying an app on nodejitsu is very simple:

jitsu deploy

Also if you need any help, just poke your head into the chat http://webchat.jit.su

Enjoy!

Deploying NodeJS apps has been painful in my past. I have used Heroku in the past, but I think I found my new love...Nodejitsu. You can see my latest open source project "Kano" by pointing your browser towards http://kano.jit.su. Deploying an app on nodejitsu is very…

Read More