Zhongde Liu

This is my personal "Clipboard" of web development stuff I come across

Leave a comment

npm, node-gyp error and Windows

I wanted to try out the Sails framework. On installation (npm install sails) however I just got this error and the installation was unsuccessful.

npm ERR! ws@0.4.32 install: `(node-gyp rebuild 2> builderror.log) || (exit 0)`
npm ERR! spawn ENOENT

It is the same thing as in this closed issue on github. There was a reference to a buggy version of ws/socketIO. Googling some more you get a lot issues related to socketIO and Windows7 or this topic in general. For example:  https://github.com/websockets/ws/issues/240 or http://stackoverflow.com/questions/15200184/why-do-i-get-error-when-trying-to-install-socket-io-with-nmp

In fact as a windows(7) user you may stumbled upon these node-gyp error previously…. nody-gyp is used “for compiling native addon modules for Node.js”. Unfortunately the prerequisites on Windows are Python and Visual Studio!?. Including also several steps for a working setup… https://github.com/TooTallNate/node-gyp/wiki/Visual-Studio-2010-Setup.

I thought  “What the …”. I just wanted to try something out.

End of story: I used “–force” on the install command and it worked. But for how long and what actually happened or did not happen behind the installation curtain!? I hope node-gyp, or the related modules (ws) will get updates to fix these hurdles on windows machines…


Update: As of now Sails(0.11.0) and socketIO(1.3.5) are installing just fine on windows…


Create/start a simple local HTTP Server

In order to develop or test some static code, without copying them into your apache webroot or something else, you easily can start a simple static webserver within the directory you are currently in with following tools.
Because you sometimes you just need a http:// (likely localhost) Url instead of a file://… one.

  1. If you have Python (https://www.python.org/) installed you can start a static web server with following command, depending on the installed version.
    python -m SimpleHTTPServer [port]//python2
    python3 -m http.server [port]//python3
  2. If you have PHP > 5.4.0 (http://php.net/) installed you can start one with:
    php -S localhost:[port]
  3. Using Ruby (https://www.ruby-lang.org/) you setup a simple server with this command:
    ruby -run -e httpd . -p [port]
  4. For node.js (http://nodejs.org/) I use the  “simple, zero-configuration command-line http server” package (https://www.npmjs.org/package/http-server).
    After the default npm installation

    npm install http-server -g

    you just type

    http-server -p[port]

    into your console.

These are some nifty tools (or “oneliners“), when it comes to browse a static/client app/website/file with your browser in your local environment without copying the files somewhere else.

Leave a comment

Build tools: Grunt – gulp – npm run

Grunt (http://gruntjs.com/) is the de facto standard regarding (frontend) build tools.

But there are alternatives.

Especially gulp (http://gulpjs.com/) is getting a bit of a momentum. gulp has a more “coding” mentality in contrast to the configuration heavy grunt setup.  It already has all the essential plugins (jshint, uglify, sass, less, etc…) for a sophisticated build workflow. In my opinion the coding style within the gulpfile offers  more readability than the big configuration objects  in gruntfiles.

Another way is to (“mis-“)use the “npm run” command to run scripts/commands, which are noted in the “scripts” field within the package.json file. James Halliday wrote a nice blog post about it: http://substack.net/task_automation_with_npm_run.

Of course there are the classical ways to perform a build: make, ant, rake, etc…

1 Comment

Reference: Zen Coding Syntax



<div id="content" class="wrapper>


For CSS:

Cheatsheet (PDF):