StrongLoop Node.js Weekly Review – Oct 27, 2014

Here’s this week’s recap of the Node.js related content we posted last week…

Blogs

The Road to a Foundation for Node.js

Today the Node.js project took a historic step forward. An advisory board is being formed for Node.js with the intention of guiding the project toward a community-based open governance model. At StrongLoop we are of course participating on this advisory board and we’re excited to serve alongside community members such as IBM, Netflix, npm, Paypal, Walmart and Yahoo.

Read more…

New Node.js LoopBack Example Applications and Tutorials

It’s always easier to learn something from an example. At StrongLoop, we know this well, so we created a multitude of example apps to go along with LoopBack. To this end, new StrongLoop engineer Simon Ho has been working to update the LoopBack example modules, and writing comprehensive READMEs that walk you through the steps to recreate each app. He’ll be continuing his work in the coming weeks, but here’s a list eigth new or recently-updated examples…

Read more…

Writing Modular Node.js Projects for Express and Beyond

In this article, I propose a minimal and flexible pattern that I think works well for projects that are larger or have the potential for growth. The original ideas stem from earlier work done by TJ Holowaychuk. As you read through the explanation and implementation, note the discussion really has little to do with Express directly and applies to any large Node project..

Read more…

New Videos

Developing APIs with Node.js and LoopBack.io

In this video, Dennis Ashby, head of client services at StrongLoop, gives you a quick preview into just one of the many things he covers in his two-day Node.js and API Development Training. In this teaser he shows you how to quickly get started building and managing APIs using the Loopback framework and an Amazon API. For more information about Node.js training visit: strongloop.com/node.js/training/

Building high quality services at Uber with Node.js

In this video Raynos (Jake Verbaten) talks about how Uber builds high quality services. He explains what it takes to “productionize” a Node.js service and shows some of the tooling Uber has built and open sourced to enable it. Recorded on Oct 16 at the SF Node Meetup.

Introduction to Error Handling and Callbacks

Check out this lightning talk by Alex Gorbatchev on managing error handling, callbacks and promises in JavaScript and Node.js from the Oct 16, 2014 SF Node Meetup.

Express.js Crash Course

In this video, Tony Pujals takes on a crash course of Express.js working through ten basic lessons with code examples to boot. Recorded on Oct 16th, 2014 at the SF Node Meetup.

In Portuguese

A branch de release do Node v0.12 chegou – e o que está acontecendo?

Ontem tjfontaine criou a branch de release do Node v0.12. O que pode significar que há um lançamento iminente, mas como TJ é o responsável pela data de lançamento, então não tem como sabermos uma data exata. A nossa opinião é que ainda pode demorar um pouco. Isso é só a branch de release.

Translation by Igor Ribeiro Lima

Read more…

What’s next?

  • Ready to develop APIs in Node.js and get them connected to your data? Check out the Node.js LoopBack framework. We’ve made it easy to get started either locally or on your favorite cloud, with a simple npm install.

The Road to a Foundation for Node.js

Today the Node.js project took a historic step forward. An advisory board is being formed for Node.js with the intention of guiding the project toward a community-based open governance model.

At StrongLoop we are of course participating on this advisory board and we’re excited to serve alongside community members such as IBM, Netflix, npm, Paypal, Walmart and Yahoo.

We believe evolving the current governance model to a truly open one supported by an independent foundation will help mainstream innovations in Node sooner, give developers and organizations the confidence to continue to invest development resources in Node, and launch a virtuous cycle accelerating the popularity and growth of Node even further.

The future for Node is incredibly bright and are excited to collaborate with the other members of the advisory board to drive its continued success.

What’s next?

  • Big brands are choosing Node. Learn why.
  • Did you know StrongLoop is the biggest contributor to Node v0.12? Read about all the new features and performance improvements coming in the next release.
  • Node is for APIs. Learn how StrongLoop is helping organizations develop and scale APIs built in Node.

A branch de release do Node v0.12 chegou – e o que está acontecendo?

Ontem tjfontaine criou a branch de release do Node v0.12. O que pode significar que há um lançamento iminente, mas como TJ é o responsável pela data de lançamento, então não tem como sabermos uma data exata. A nossa opinião é que ainda pode demorar um pouco. Isso é só a branch de release.

Os cincos dos dez colaboradores mais ativos do Node v0.12 são patrocinados por nós. Embora os lançamentos sejam controlados por TJ, nós temos bons contatos na comunidade e uma noção do que acontece na codebase. No momento não há uma versão estável da libuv na branch v0.12 e, antes do lançamento real, essa lib ainda precisa ser melhorada.

Além disso, há consenso entre os colaboradores que a API asyncListener não está pronta e deve ser removida antes do lançamento. Nota: essa remoção já foi feita, graças a trevnorris. Existem alguns bugs pendentes que consideramos um impedimento e que podem ser descobertos mais em breve. Nós achamos que TJ simplesmente estaria criando uma branch de release para que a versão v0.12 fosse congelada e estabilizada (ainda pode levar semanas até o lançamento).

Se você ainda não está familiarizado com os recursos da versão v0.12, aqui estão as novidades.

Read more

New Node.js LoopBack Example Applications and Tutorials

It’s always easier to learn something from an example. At StrongLoop, we know this well, so we created a multitude of example apps to go along with LoopBack. However, the core LoopBack engineers have been too busy adding new features, fixing bugs, and moving the framework forward and to devote time to updating example apps. To this end, new StrongLoop engineer Simon Ho has been working to update the LoopBack example modules, and writing comprehensive READMEs that walk you through the steps to recreate each app.

He’ll be continuing his work in the coming weeks, but here’s a list of recently-updated examples:

These are added to the existing LoopBack 2.0 examples:

More are coming soon, including:

AngularJS Starter Example

Many folks on the LoopBack Google Group have expressed interest in learning more about the LoopBack AngularJS SDK. One of the new tutorials, the AngularJS Starter Example is devoted to just this, so we’ve included it below… Enjoy!

This example demonstrates how to use LoopBack with AngularJS. It’s a simple “To Do” list application that uses LoopBack on the back end and AngularJS on the front end.

angular-starter

Prerequisites

Before starting, makes sure you’ve followed Getting Started with LoopBack to install Node and LoopBack.

Install Bower to manage front-end dependencies:
$ npm install -g bower

In addition, you will need a basic understanding of:

Trying out the application

First, run the application so you can understand what it does:

$ git clone https://github.com/strongloop/loopback-example-angular
$ cd loopback-example-angular
$ npm install
$ slc run

You’ll see a screen such as that shown above.  Enter a couple of “To Do” items, and click Add or press Return to add the item to the list.  Then delete an item by the clicking the “x” to its right.

That’s basically it –a very simple app.  Note that if you stop the app (with Ctrl-C) and restart it, all your “To Do” items will be preserved.

Procedure

Follow the steps below to create the application from scratch.

1. Create the application
Run slc loopback, and name the app my-lb-angular-starter.

 

2. Configure the data source
Edit server/datasources.json to look like:

This change will persist model instances to a JSON file. For more information, see the memory connector documentation.

 

3. Create the Todo model

Enter this command:
$ slc loopback:model
Respond to slc’s prompts as follows:

  • Use the memory connector
  • Expose the model via REST
  • Keep the default plural form
  • Add a required String property called “content”.

 

4. Add some model data
Start the server:

$ slc run

Then load localhost:3000/explorer in your browser.

angular example explorer

 

Under Parameters, click in the Model Schema field to automatically copy the JSON data template to the data field. Then edit the Todo item in the data field to look as follows:

Leave the id property alone; LoopBack will automatically increment it each time you add a new model instance.

 

5. Verify the model instance has been inserted
Open db.json; it will be in the application root directory. You will see this:

Notice the “Todo” property contains the model you just created.

 

6. Configure the vendor directory
Create a .bowerrc file in the application root directory with the following contents:

Bower installs packages in bower_components by default, but this setting changes it to client/vendor instead to make it easier to import files into index.html.

 

7. Install front-end dependencies
In the application root directory, enter:

 

8. Create index.html
Create index.html In the /client directory and add the following contents from the basic Bootstrap getting started template:

 

9. Create stylesheet
Create a css directory inside the client directory. Inside the newly created directory, create a file named style.css with the following contents:

 

10. Add Bower dependencies
Modify index.html to look like the following.  Note: For your production app, use the minified versions of Bower dependencies.

 

11. Configure index.html to be the application entry point
Remove server/boot/root.js and modify server/server.js to look like this:

 

12. Create app.js and configure application routes
In the client directory, create another directory named js. Inside the js directory, create a file named app.js with the following contents:

For more information on application routing, see AngularUI Router documentation.

NOTE: If you’re using jshint, you can add “predef”: [‘angular’] to .jshintrc to prevent Angular specific warnings.

13. Add apps.js as a dependency in index.html:

 

14. Create todo.html
In client/js, create a directory named todo. Inside the todo directory, create another directory named templates. In this directory, create a file named todo.html with the following contents:

 

15. Create controllers.js
In client/js/todo, create controllers.js with the following contents:

 

16. Add controllers.js as a dependency in index.html:

 

17. Generate LoopBack Angular services file, lb-services.js
Create a new directory named common in client/js. Change to the common directory and run this command:

This generates a file named lb-services.js which is an Angular service used to interface with your back-end application. For more information, see the LoopBack AngularJS SDK.

18. Declare lb services as a dependency.
Edit client/js/app.js and add the following:

Also add lb-services.js as a dependency in index.html:

 

19. Run the application
From the project root, enter slc run and browse to localhost:3000 to view the application.

More information

For more information, see the LoopBack Angular SDK documentation.

What’s next?

  • Ready to develop APIs in Node.js and get them connected to your data? Check out the Node.js LoopBack framework. We’ve made it easy to get started either locally or on your favorite cloud, with a simple npm install.

 

Writing Modular Node.js Projects for Express and Beyond

I have worked with Express for over four years now and I cannot count how many different ways I have reorganized my code! Express bills itself as an un-opinionated framework. This is true. If you search for “express boilerplate” you will find a lot of different ways to organize your project.

In my experience, there isn’t “one best way” to structure a project. If you are looking for that, you probably won’t find it. That’s not to say there aren’t things that work better than others.

In this article, I propose a minimal and flexible pattern that I think works well for projects that are larger or have the potential for growth. The original ideas stem from earlier work done by TJ Holowaychuk. As you read through the explanation and implementation, note the discussion really has little to do with Express directly and applies to any large Node project.

Modularizing the code base

It’s hard to anticipate how a code base will grow and change. An application needs the flexibility to adapt and enough isolation between components to enable code reuse and lessen cognitive overhead.

A modular structure understands that you won’t have complete isolation between the components. There will be overlap and that’s OK and sensible[1]. A modular structure then:

  1. Enables an application to be separated into smaller components.
  2. Permits components to have their own dependencies (and tests) that can be updated with minimum to no effects on other components.
  3. Allows project-wide dependencies that can be shared (or overwritten) by individual components.
  4. Makes requiring components first-class. In other words, does not use relative require statements.
  5. Empowers an application to grow (or shrink) without a lot of reshuffling.

The Node mantra of small npm modules is carried over then into small components.

Read more