# data[].attributes.body
Y pensar que todavía hay ingenieros que hacen testing porque no les gusta programar.

Hace tiempo que el ingeniero de QA dejó de ser un planillero :)

# data[].attributes.body
peligroso como los monos, pero es lo que hay

# data[].attributes.attachment_link.readable_text
A walkthrough on how to create and deploy a basic site with Node.js and the Express framework. Examples of generating an express site, how to use templating and styles, creating basic routes and deploying the app to the Internet.

Table of contents

What we are going to do

This walkthrough will go over setting up a basic site using Node.js and Express. The walkthrough is aimed at beginners exploring Node.js as I've had many questions from friends and colleagues about creating and deploying node apps. If you are not a beginner the article probably won't be of much use to you. We are going to use express, an excellent web framework for node created by TJ Holowaychuk who seems to be pumping out Node.js libraries like he was ten men.

Here is the site we are going to create. You might also want to grab the source code.

Setup

First we need to setup our development environment. If you are on OSX I've covered how to setup Node.js and npm on OSX in a previous article. If you haven't got everything installed follow that article.

If you are on Linux there are plenty of articles on Google.

For Windows users there are also resources on Google but it is a bit more tricky.

Prerequisites

If everything has installed ok you should now have Node.js and npm running on your machine. At the terminal type node -v and npm -v and you should see something like:

node -v v6.7.0 npm -v 3.10.8

Create an Express site

Still with me? We've covered a lot already! Now let's create an Express site.

First let's install express

npm install -g express-generator

You may find that you get a permissions error. If this is the case rerun the command with sudo.

sudo npm install -g express-generator

The -g flag means that you are installing express globally on your system.

Now we can create an express application.

express -c stylus express_example

The -c states that we want to use stylus for css. You should see the following output:

create : express_example create : express_example/package.json create : express_example/app.js create : express_example/public create : express_example/routes create : express_example/routes/index.js create : express_example/routes/users.js create : express_example/views create : express_example/views/index.jade create : express_example/views/layout.jade create : express_example/views/error.jade create : express_example/bin create : express_example/bin/www create : express_example/public/javascripts create : express_example/public/images create : express_example/public/stylesheets create : express_example/public/stylesheets/style.styl install dependencies: $ cd express_example && npm install run the app: $ DEBUG=express_example:* npm start

As per the instructions you'll need to install dependencies so do this

cd express_example && npm install

This will install packages and you will see a lot of output. When this is complete you can boot your application.

Boot the app

That's all the setup you need. Phew. Now you can boot the app. If you are on OSX or Linux use the following command.

DEBUG=express_example:* npm start

If you are on Windows use the following command.

set DEBUG=express_example:* & npm start

You should see Express server listening on port 3000 and if you open http://127.0.0.1:3000 you'll see the default Express page.

Using Git

Git is a version control system that is used heavily in the Node.js ecosystem, particulary with Github. If you aren't familiar with Git Scott Chacon is your go-to man. He's written extensively and eloquently on Git for beginners and experts. Checkout Gitcasts for if you are a beginner and ProGit for more advanced stuff. We are going to use git to version our site and publish it so let's set up our repo now. If your Express server is still running hit CTRL + C to stop it.

git init echo 'node_modules' > .gitignore git add . git commit -m 'initial commit'

Developing Node.js sites

Normally when you develop a Node.js site you'll need to restart your application each time you make a change. Thankfully our home-grown British JavaScript genius Remy Sharp has solved this problem with nodemon. Nodemon will reload your application each time it changes so you don't need to restart it. If you have used Shotgun for Ruby with Sinatra it is similar to that. To install run

npm install -g nodemon

Then you can start your app with

DEBUG=express_example:* nodemon

Nodemon automatically looks in your project setting to find the appropriate files and setting to start your server. If this does not work try:

DEBUG=express_example nodemon npm start

Using nodemon means you don't have to restart your app each time you make a change. For more infomation on nodemon see the README

HTML in Express

Express is agnostic as to which templating language you use. Templating languages can be a hot topic of debate but for this article I'm going to use jade. If you've used haml it is similar to that. In the example we use jade to setup a layout template.

doctype html head title= title link(rel='stylesheet', href='/stylesheets/style.css') link(rel='stylesheet', href='/stylesheets/chunkfive-fontface.css') body header nav ul li a(href="/") Home li a(href="/about") About li a(href="/contact") Contact section#wrapper block content footer section.css-table section.four-column section.cell p Mauris porttitor <br />felis eu leo aliquet<br /> ac rutrum odio aliquet section.cell p Mauris porttitor <br />felis eu leo aliquet<br /> ac rutrum odio aliquet section.cell p Mauris porttitor <br />felis eu leo aliquet<br /> ac rutrum odio aliquet section.cell p Mauris porttitor <br />felis eu leo aliquet<br /> ac rutrum odio aliquet

Save this file as /views/layout.jade overwriting the file created by the generator. This is a common template we can reuse. The line block content pulls in content from the page it is used on. Express also supports variables that you pass through to the template. In this case we pass the title variable. If you are coming from Sinatra this will be familiar to you. If you are not I recommend consulting the Express documentation.

CSS in Express

Again Express is agnostic to what you use to generate your CSS - you can use vanilla CSS but for this example I'm using Stylus. This is very similar to Sass and supports variables, mixins, functions and more. I really like it! Here's an example from our stylesheet

body font 62.5%/1.5 Helvetica, Arial, "Lucida Grande", "Lucida Sans", Tahoma, Verdana, sans-serif text-align center background #000 #wrapper width 920px text-align left margin-left auto margin-right auto background #fff padding 20px border-bottom-radius(15px)

You'll see that stylus is very terse - you don't need brackets or commas.

Routing in Express

Routing is similar to Sinatra, allowing you to set up RESTful routes.

In this example we setup three routes in routes/index.js

var express = require('express'); var router = express.Router(); router.get('/', function(req, res){ res.render('index', { title: 'Home' }); }); router.get('/about', function(req, res){ res.render('about', { title: 'About' }); }); router.get('/contact', function(req, res){ res.render('contact', { title: 'Contact' }); }); module.exports = router;

See the Express documentation for more.

Publishing your site

We've now developed a basic Node.js site using express and we want to host it somewhere. Publishing the site to Heroku is free and you can be up and running in no time. You can sign up for an account at Heroku for free and then install the toolbelt.

Then you can use the command line tools to create a site on Heroku and publish it.

heroku apps:create git push heroku master

After some output you should see that your application is deployed and a line with the url of your application. Copy and paste the URL and open it in your browser. You should see your application deployed on the Internet.

remote: https://[yoururl].herokuapp.com/ deployed to Heroku

Conclusion

This article has showed how to create a very basic site using Node.js and Express. It has introduced a number of things from the Node.js ecosystem and showed you how to deploy the app to Nodester.

The strengths of Node.js as a technology are not so much in building static websites like this. I encourage you to explore some of the Node.js libraries to see what it can do. Particularly for real-time applications Node.js is extremely exciting and I think we'll see some great apps built on Node.js. Try starting with socket.io for a taste of what to expect.

If you find any inaccuracies in the post send me an email and I'll update the post.

Further reading

Have an update or suggestion for this article? You can edit it here and send me a pull request.

Tags

Recent Posts

Using HashiCorp Vault with LDAP
How to use HashiCorp Vault to setup an LDAP backed secret store with read-only access for users in groups and read-write access for specific users

Linux and Unix xargs command tutorial with examples
Tutorial on using xargs, a UNIX and Linux command for building and executing command lines from standard input. Examples of cutting by character, byte position, cutting based on delimiter and how to modify the output delimiter.

Copy a file in Go
How to copy a file in Go. The ioutil package does not offer a shorthand way of copying a file. Instead the os package should be used.

About the author

George Ornbo is a hacker, futurist, blogger and Dad based in Buckinghamshire, England.

He is the author of Sams Teach Yourself Node.js in 24 Hours. He can be found in most of the usual places as shapeshed including Twitter and GitHub.
← http://shapeshed.com
Content is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)

# data[].attributes.attachment_link.title
Creating a basic site with Node.js and Express | George Ornbo

# data[].attributes.attachment_link.description
This walkthrough will go over setting up a basic site using Node.js and Express. The walkthrough is aimed at beginners exploring Node.js as I've had many questions from friends and colleagues about creating and deploying node apps. If you are not a beginner the article probably won't be of much use to you.

# data[].attributes.attachment_link.description
Discover thousands of offerings - from free courses to full degrees - delivered by world-class partners like Harvard, Google, Amazon and more.

# data[].attributes.attachment_link.readable_text
I like to think of the private cloud market as existing in two distinct eras - Before OpenStack and Anno OpenStack. It is now 3 A.O. (well, in a few months), and Oracle's announced acquisition of Nimbula on Wednesday got me thinking of just how much the world has changed since OpenStack officially launched on July 18, 2010.

A report I wrote for GigaOM Pro in June 2010 (subscription req'd), entitled "Defining Internal Cloud Options: From Appistry to VMware," seems like a good starting point for a private-cloud startup edition of "where are they now." Ignoring the public companies on the list for the time being (with the exception of CA), here's what has happened to the private companies and startups.

1. Abiquo has a new CEO, a tight partnership with NEC around selling to service providers and appears focused on the European market. The company raised about $14 million in 2010, but hasn't really made a lot of noise stateside since then.

2. Appistry made a huge shift in August 2011 and it now positions itself as a platform for running high-performance applications in areas such as life sciences, defense and financial services. Its biggest area of focus is genomics, where it is even developing new methods for analyzing genomes.

3. CA bought a bunch of cloud startups in 2009 and 2010 - Cassatt, 3Tera, Oblicore and Nimsoft among them - but it has been essentially silent since then in terms of real innovation. Maybe these acquisitions are driving big business, but I was expecting a more-visionary strategy in terms of fusing them into a cohesive and forward-looking whole.

4. Winner!!! Cloud.com had big-name users and workable technology, and it sold itself to Citrix for more than $200 million in 2011. It has since launched an open source competitor to OpenStack called Apache CloudStack and appears to be doing good business.

5. Enomaly's products still technically exist, but Virtustream bought the company in 2011 with the primary goal of repurposing its intellectual property in the realm of cloud federation and gaining a toehold in China.

6. Eucalyptus Systems: If you ask CEO Marten Mickos, everything is great with Eucalyptus, and its whopping $55.5 million in venture capital (including a $30 million round in April 2012) and tens of thousands of downloads of its Amazon-compatible cloud softwware are proof. Ask anyone else and they'll likely tell a different story.

7. GigaSpaces: GigaSpaces appears to be doing well enough, although it was around well before the term "private cloud." It has always been much more about its in-memory data grid tech and apps that need dynamic scalability, although it does now offer a Platform-as-a-Service product that's somewhat disconnected from the legacy business.

8. Joyent has always been respected for its engineering chops, although rumors sometimes swirl about how much business the company - which has raised an incredible $115 million - is actually bringing in. Still, it continues to improve its public and private cloud offerings and has landed some big-name users.

9. Librato looks to have abandoned its resource-management product line to focus on measuring stuff - sensors, server use, whatever. It wears that hat well, and Heroku is among its loyal users.

10. LongJump: In hindsight, LongJump's business was not actually a great fit for that 2010 report, and its business appears about the same: you build apps in a user-friendly setting and they can run on LongJump's infrastructure or your own.

11. Morphlabs is the master of pivots, although it's still hanging around and pushing out new products. Now an OpenStack-based cloud-software vendor, it released a new service-provider-focused platform called mCloud Osmium in February.

12. Nimbula, as noted above, is now part of Oracle in a move that is widely believed to be an "acquihire" situation, although neither company will comment on the details.

13. Platform Computing: IBM bought Platform Computing in October 2011 and appears to have refocused the company around its HPC roots. Not that that's a bad thing - Platform was a $72 million company on its own in a niche market, and I'd guess IBM paid a fair price for it.

14. Virtustream: Another winner! Virtustream has been on fire since 2010 (actually buying up Enomaly) and looks to be the darling of the enterprise cloud space. It's primarily a public cloud provider, but it has a strong private/hybrid cloud business that ties Virtustream back to customers' data centers.

15. Voxel: Voxel, whose main business was a public cloud offering, got acquired for $30 million by managed hosting provider Internap in January 2012.

OpenStack is what happened to the private cloud market and forced so many acquisitions, pivots and even one closure. Users, investors and everyone, really, were waiting for some promise of cloud interoperability and portability (aka something other than Amazon, VMware or Microsoft) and OpenStack delivered it. Further, for the service provider community - which has arguably bolstered the sales of private cloud software since its inception - OpenStack provided a relatively engineering-free path to public cloud offerings (compared with building their own from scratch, that is) without fear of being at the mercy of a startup that might fold tomorrow and take its core technology with it.

I haven't run the numbers, but I'd be willing to bet the majority of venture capital going toward "private cloud" in the past two years has gone to OpenStack-based startups. We've also seen nearly every large software vendor pin its cloud ambitions to OpenStack to some degree - Cisco, HP, IBM and Red Hat to name a few. Even Rackspace is now in the private cloud game thanks to OpenStack.

For buyers, a large, well-heeled and deep-pocketed community has to be more appealing than a disparate collection of startups all doing their own thing.

Who's not doing OpenStack (at least in any meaningful way)? VMware, Microsoft, Amazon Web Services - all companies with their own intellectual property, huge user bases and lots of money to back their visions. They all also have strong public cloud connections (some, obviously, stronger than others).

The cloud startups from 2010 that are still arguably thriving today share similar characteristics. They've been big on engineering, won major customers early on and raised a lot of money to help them maintain through any tough times. All but Cloud.com, now part of Citrix, have a very prominent public cloud component, too - which appears critical for a truly seamless hybrid environment - but it has staked out its own claim as the anti-OpenStack.

All of the aforementioned companies are/were doing infrastructure as a service primarily, but we're already seeing a similar thing happen in the platform-as-a-service space thanks to Cloud Foundry. Providers that weren't part of that community are jumping on board, and it's just a few established holdovers that look like they'll be able to push forward without riding Cloud Foundry's coattails.

Perhaps this is telling for how the future of anything at the infrastructure or platform layers is going to play out. You're either really early and really good, or you wait for an open source project - OpenStack, Cloud Foundry, Hadoop, Open Compute, OpenFlow, etc. - and try to build on that. There's following fast, and there's following smart.
Feature image courtesy of Shutterstock user Alexey Repka.

# data[].attributes.attachment_link.title
How OpenStack upended the private cloud market overnight

# data[].attributes.attachment_link.description
I like to think of the private cloud market as existing in two distinct eras - Before OpenStack and Anno OpenStack. It is now 3 A.O. (well, in a few months), and Oracle's announced acquisition of Nimbula on Wednesday got me thinking of just how much the world has changed since OpenStack officially launched on July 18, 2010.

# data[].attributes.attachment_link.readable_text
Google Drive lets users create Docs, Sheets, and Slides, collaborate on them in real time, and have their changes saved automatically. With the new Google Drive Realtime API, you can now easily add some of the same real-time collaboration that powers Google Drive to your own apps. This new API handles network communication, storage, presence, conflict resolution, and other collaborative details so you can focus on building great apps.

Developing for the Drive Realtime API is almost as simple as working with local objects. The API provides collaborative versions of familiar data objects such as maps, lists, strings, and JSON values and automatically synchronizes and stores modifications to these objects. Your application reads from and writes to these objects like any other local object. Change event handlers can be added to collaborative objects so that your app can react to changes from other collaborators.

Because the Drive Realtime API is based on operational transformation (OT), local changes are reflected instantly, even on high-latency networks. The Drive Realtime API automatically transforms changes to the data model so that every collaborator stays in sync.

If basic collections aren't enough for your application, the Drive Realtime API supports custom objects and references, including trees and arbitrary graph structures. As with other collaborative objects, the Drive Realtime API automatically synchronizes these objects with other collaborators and stores them in Drive.

Because presence is important in collaborative applications, the Drive Realtime API also keeps track of who is connected to your application and provides your app with events for when collaborators join, leave, or make changes.

Neutron Drive, Gantter and draw.io have enabled realtime collaboration in their apps using the Google Drive Realtime API. Check out these apps to see the Drive Realtime API in action.

Collaborative code editing with Neutron Drive

Neutron Drive is an online editor for text and source code files stored in Google Drive. You can now collaboratively edit any text or source code files stored in Drive and get a realtime collaboration experience-shared typing, a view of active collaborators, cursor positioning, and selected text. This all comes in addition to the syntax highlighting and other advanced features offered by Neutron Drive. To learn more, watch the video:

Collaborative project scheduling with Gantter

Gantter is a free online project scheduling tool and Gantt diagram editor. It now allows you to collaboratively-and in real time- work on your project schedules. It even features an embedded chat powered by the Drive Realtime API. Watch the video below to see Gantter's new realtime collaboration features in action.

Collaborative diagraming with draw.io

draw.io is a diagraming application that enables you to draw a wide variety of diagrams such as flowcharts, UML diagrams and even electronic circuits. You can now see updates from other collaborators instantaneously, with colored visual cues indicating who has changed the diagram and where that change occurred. Try the new draw.io collaborative beta at rt.draw.io and watch the video below.

Learn more about the Drive Realtime API

We built a collaborative colored cube puzzle so you can have some fun while trying out the Drive Realtime API and a Drive Realtime API Playground to take you through the API step-by-step. Both apps are open source so check out our Github repos.

Have a look at the Google Drive Realtime API technical documentation and start making your app realtime-enabled!

Brian Cairns joined the Google Drive team in 2011 and lives in Boulder, Colorado. He is the lead software engineer for the Drive Realtime API.

# data[].attributes.attachment_link.title
Build collaborative apps with Google Drive Realtime API

# data[].attributes.attachment_link.description
Google Drive lets users create Docs, Sheets, and Slides, collaborate on them in real time, and have their changes saved automatically. With the new Google Drive Realtime API, you can now easily add some of the same real-time collaboration that powers Google Drive to your own apps.