I just published an in-depth tutorial that covers how to configure a complete server stack over on the Ghost Inspector blog. I had a great experience building out Ghost Inspector’s infrastructure and wanted to share some details about what can be accomplished nowadays for just $50/mo. It’s a thorough article and walks you through the configuration of the various servers you’ll be needing: web, app, api, database, load balancer, etc. Give it a look!
# Define my class class myClass # Define a method within my class doSomething: -> console.log("Hello world!") # Add to exports for node, or window for browser if typeof module isnt 'undefined' and module.exports module.exports = new myClass() else 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") myClass.doSomething()
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.