# Define my class
# Define a method within my class
# Add to exports for node, or window for browser
if typeof module isnt 'undefined' and module.exports
module.exports = new myClass()
this.myClass = new myClass()
First, we create a class named "myClass" and add a method to it. Then, with a simple if statement, we can determine whether we’re running this code in Node.js or in the browser and export the class accordingly. Let’s assume we’re compiling this down into "my-class.js".
In Node.js, we would use the class like this:
myClass = require("my-class")
In the browser, we would use the class like this:
Grunt.js is a task runner that comes with various plugins for compiling, building, formatting, etc. within your project. I covered some of the basics of using this tool in my article about using Grunt Watch and LiveReload for real-time compilation.
I recently setup a simple deployment process using Grunt, so I thought I’d share the details. I found a couple deployment-related Grunt plugins out there, but they didn’t really suit my needs. Instead, I opted to simply use the grunt-ssh plugin to connect to my server and run the necessary commands to update, build and restart my application. Let’s take a look at a simplified Gruntfile.coffee.
I’ve been doing a lot of backend development in Node.js recently. Node.js runs on a single threaded event loop and leverages asynchronous calls for doing various things, like I/O operations. While other languages will send a database query and wait there for the result to come back, Node.js will not. When you send a database query, Node.js will continue executing the code that comes after it, then jump back when the result is available.
Today was the public launch of the Ghost blogging platform (well, technically yesterday, I guess). If you haven’t heard of Ghost yet, check out this page (and video). In short, Ghost is a new, minimalist blogging platform. The project lead is John O’Nolan who previously worked at WordPress and created a Kickstarter project with the intention of building a more streamlined blogging platform (since WordPress has become rather bloated).