Yeoman Generators and permissions on OSX

So here is a tip for OSX users with permission problems when using a Yeoman Generator.

Today, I attempted to install kraken.js…

$ sudo npm install -g yo generator-kraken
$ yo kraken

and I kept running into permission issues.  I had reinstalled multiple versions of node & npm with the same results…

npm ERR! Error: EACCES, mkdir ...
...
npm ERR! Please try running this command again as root/Administrator.

The real problem here is that I should not have to be logged in as root to run this script. (And also, running under sudo didn’t fix the problem anyway.)

So, if you are having this problem, take a look at your ~/.npm/ directory.  Mine looked like this…

It looked like Yeoman was choking on modifying directories owned by root.  Which of course is good behavior.  What probably happened is I had installed some stuff at some point as root.  Which is of course bad behavior :-/

The fix was straightforward…

cd ~/.npm/
sudo chown gshipon:staff *

Now all is kosher in ~/.npm/

Screen Shot 2014-06-25 at 4.34.04 PM

And kraken.js is happy 🙂

Screen Shot 2014-06-25 at 5.29.38 PM

Punching up “The Lab”

So, when I got to the lab today there was this…

Image

That’s right: a sign. Backlit by a fluorescent bulb – it says “the lab”.   No note, no invoice, no explanation.

While there is still mystery surrounding this strange, yet appropriate, object’s origin and meaning, my guess is some adoring co-worker (maybe from Finance, maybe from Design) found this at a garage sale and anonymously dropped this off before we got in.  Fanmail.

Anyways, we plug it in and it takes about 5 minutes for us to think of things we could *do* to it.

From there it doesn’t take long for Doug to whip out an Arduino board and coil of neo-pixel.

Image

Here it is in pictures…

Image

 

Image

 

Image      Image

There you have it people.   Code and specs are here…

Super Simple Node+Express HTTP Server

file///Users/Garris/Sites/myApp/index.html

During web-app development, I usually need an easy way to serve my app locally. To do this I’ll either work off of a remote server or I will serve the files locally. In the past I would have used a LAMP package for this — but since I started using a Node+Express server to host the files I’ve never looked back.

Here’s a quick tutorial for anyone coming from LAMP wanting to try out Node/Express…

First, you’ll need to have Node & NPM installed. Node is the awesome javascript based application enviornment and NPM is the package manager that makes it easy to add open-source superpowers to that enviornment.

Go here, do that…

http://nodejs.org/download/

Next you’ll want to install express.js, this is the goto framework for making web services with Node.

We will add Node+Express resources in parallel with our app’s root directory. IOW: Navigate to the root directory of your app, then navigate up one directory.

In my case it’s $ cd ~/Sites/

In that directory, add a file called package.json with the following contents

{
	"name": "spaServer",
		"description": "express app that serves index.html",
		"version": "0.0.1",
		"private": true,
		"dependencies": {
		"express": "3.x",
		"underscore": "~1.6.0"
	}
}

In that same directory, run $ npm install

Node will look at package.json and download everything you need into ./node_modules

Finally, for the server app. Create a file called server.js with the following contents…

var 	
	express = require('express')
	,app 	= express()
	,_ = require('underscore')
	,util 	= require('util')
	,os 	= require('os');


var 	
	rootDir = __dirname + '/app'
	,port 	= 3000;
	
	
app.use(express.static(rootDir));
	
app.listen(port);


//===================
console.log('Serving files from: '+rootDir)
console.log('Listening on: ' + getAddresses() + ':' + port + '');
console.log('Press Ctrl + C to stop.');


function getAddresses(){
	var 
	 	interfaces = os.networkInterfaces(),
		addresses = [];
	
	_.each(interfaces,function(net){
		_.each(net,function(address){
			if (address.family == 'IPv4' && !address.internal) addresses.push(address.address);
		})
	})

	return addresses;
}

Start the server by entering $ node server.js and you should see…

$ node server.js
Root: ~/Sites/app
Listening on 10.0.0.23:3000
Press Ctrl + C to stop.

That should do it. Now my URL looks like this…

…and I can test the project on other local devices with the url that displays in the console.