background preloader

Node.js stuff

Facebook Twitter

Scaling Isomorphic Javascript Code — blog.nodejitsu.com. Whether your using Angular, Ember.js, BigPipe or any other framework, all have dealt with seperation of concern issues. Today an increasing number of frameworks are adopting patterns that are similar on both client and server side. Chosing the right framework for the problem at hand is tricky, try them all on our platform for free, sign up now. Take a minute and think about how often you've heard the phrase "Model-View-Controller" (or MVC). Do you really know what it means? At a high-level it is about a separation of concerns between the major areas of functionality in presentation-centric applications built on retained graphics systems (i.e not-raster graphics, such as games). Dig a little deeper and it becomes obvious that it is just a bucket term for a lot of different things.

This approach has been acceptable for other languages such as Java, Ruby, and Python it is simply not good enough for Node.js for one reason: Javascript is now an isomorphic language. Lets dig deeper. Flatiron/plates. Edit this Fiddle. Getting Started with Socket.IO and Node.js. Node.js is not the cure for everything, however, it can certainly makes working with Websockets very easy when using the Socket.io library. Using websockets you can easily build realtime applications and even multi-player games. Today I’ll show you how to easily build a simple chat program using Node.js and Socket.io. Note: To go through this article you will need to have Node.js installed and working correctly.

You will also need some sort of text editor, I’ll be using WebStorm but anything you wish to use should work. On you computer create a new folder somewhere convenient called: chat. Let’s fill in the app.js file first. The above code is pretty bare minimum for a chat server. The index.html page is also very minimal and looks like the following: The webpage is not very attractive but it works. The next step is to install socket.io by doing the following in a terminal (or command prompt): $ npm install socket.io Run the app.js file: $ node app.js. Blog/angular-express.html. AngularJS is like the missing Batarang on your utility belt of web development awesomeness. It gives you two-way data binding that's both easy to use and fast, a powerful directive system that lets you use create reusable custom components, plus a lot more.

Express is an excellent webserver for Node.js that provides routing, middleware, and sessions. Incidentally, the two work quite well together! In this tutorial, I'm going to walk through writing a simple blog app with Angular and Express. If you'd rather skip to the end and see the finished product, you can grab the finished product from Github, or take a look at a live demo here.

Anatomy of the App This application is really divided into two parts: client, and server. Getting the Angular Express Seed To kick start the process of writing an AngularJS app, I've created the Angular Express Seed, based on the Express web server (which runs on Node.js) and the Angular Seed. or download it as a zip. λ → npm install λ → node app.js <!

Conclusion. Edwardhotchkiss/always. Dalcib/angular-phonecat-mongodb-rest. Btford/angular-express-seed. Learnode.js by Dean Sofer. How To Module. Static Version This article was written for Node v0.4.1 and is no longer applicable. As of node.js 0.6.3 NPM comes pre-installed. These are some basic steps for writing a NodeJS module. Most of the suggestions in this document are optional. You can definitely write your program however you like, and many in the node community enjoy trying out new creative ways of doing things. This is merely a set of patterns that noders have found to work for them and their projects. Use Git Most people in the node community use git for all their version control needs. Don't wait until your program is "ready" before using git on it! If you wish to share your program with others, then github is also a tremendously useful resource that most nodejs developers use.

A package.json File Create a file in the root of your program named package.json. If you plan to publish your program and let others install it using npm, then a package.json file is essential. You can specify in this file: README, and other docs Testing. Managing module dependencies. Static Version Following this discussion on the node.js mailing list about managing module dependencies, I thought it's worth sharing some pointers on that here.

Using NPM to bundle your module dependencies If you're building an application that is dependent on a number of NPM modules, you can specify them in your package.json file this way: By doing so, every time you checkout your project fresh, all you need to do to get your dependencies sorted out is: $ npm install Note that you can either require a specific version of a module, or a minimum version by prefixing the version number with >=. Managing development dependencies If you have development related dependencies (e.g. testing framework) which you do not wish to install in production, specify them using the devDependencies property: On production, using npm install --production will ensure that the development dependencies are not installed.

Managing private NPM modules Specifying a git repo as a dependency View the discussion thread. Asynchronous Control Flow with Promises. Static Version A Promise is an object that represents the result of an asynchronous function call. Promises are also called futures and deferreds in some communities. Goal of this Article The goal of this article is to introduce CommonJS promises as they exist in NodeJS user-land. With jQuery popularizing a variant of CommonJS promises for AJAX operations, promises will likely gain a broader user-base in the browser and on the server.

Brief History of Promises in Node Promises based on EventEmitters were originally a part of Node. Var promise = fs.stat("foo");promise.addListener("success", function (value) { // ok})promise.addListener("error", function (error) { // error}); The style required more allocations than necessary. Fs.stat("foo", function (error, value) { if (error) { // error } else { // ok }}); Promise Terminology Fulfillment: When a successful promise is fulfilled, all of the pending callbacks are called with the value.

Promise Libraries Server Side Q library by Kris Kowal. Thenables. Visionmedia/jade. Visionmedia/consolidate.js. Visionmedia/express. LearnBoost/socket.io. Underscore.js. Model.coffee. Mongo Model. Domain Model for MongoDB and Node.JS CoffeeScript and Fibers are optional. You can use Model with plain old JavaScript and Callbacks. class global.Post extends Model @collection 'posts' @embedded 'comments' class global.Comment extends Model Dynamic schema, flexible queries. post = new Post text: 'Zerg on Tarsonis! ' post.comments.push new Comment text: "Can't believe it! " post.save() Post.first(status: 'published') Post. find(status: 'published'). sort(createdAt: -1). limit(25). all() class global.Post extends Model @latest: -> @find(status: 'published').

Post = Post.first() post.comments.push new Comment text: 'Sad news ...' post.save() post.delete() Post.delete status: 'draft' class global.Post extends Model comments: -> Comment.find postId: @_id class global.Comment extends Model post: -> Post.first _id: @postId post = Post.create text: 'Zerg found on Tarsonis! ' post = Post.first() post.comments().limit(25).all() post.comments().count() before / after of create, update, validate and delete. Nowjs for Node - Directly call remote functions in Javascript. GivenWhenThen: Simple, Powerful Acceptance Testing for Node.js. Over the last year or so, interest in and development for Node.js has accelerated dramatically.

There is no shortage of excitement and promise in this burgeoning community and for many of the same reasons cited by others, about six months ago we decided it made sense to dive in ourselves. Coming from a committed testing background on multiple web frameworks, including Rails, we are strong adherents to BDD. Naturally the first thing we did when spinning up on the Node stack was look around for good BDD acceptance testing tools. Not finding anything that fit for us, we went ahead and rolled our own. In this post, we’ll introduce GivenWhenThen, a DSL and runner that allows anyone to easily construct acceptance tests with BDD semantics in straightforward, sentence-like statements and then run them against Sauce Labs.

Writing a Story story 'Executing a Google search', """ As a human I want to perform a search So that I can access the world's information """, -> Steps Configuration For example: Vows « Asynchronous BDD for Node. Tower.js - Full Stack Web Framework for Node.js and the Browser.