MoinMoin Logo
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Navigation

  • Start
  • Sitemap
Revision 8 as of 2014-03-11 22:24:56
  • Javascript
  • NodeJS

NodeJS

Node.js is a platform built on Chrome's Javascript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.

http://www.nodejs.org/

SlackBuild Slackware64 14.0

  • su
  • cd /tmp
  • wget http://slackbuilds.org/slackbuilds/14.0/network/node.tar.gz

  • tar xvzf node.tar.gz
  • cd node
  • wget http://nodejs.org/dist/v0.10.12/node-v0.10.12.tar.gz

  • ./node.SlackBuild

  • installpkg /tmp/node-0.10.12-x86_64-1_SBo.tgz

Package 64 bit: node-0.10.12-x86_64-1_SBo.tgz

node-gyp

node-gyp is a cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js.

https://github.com/TooTallNate/node-gyp

Install with npm

su npm install -g node-gyp node-gyp

Hello world gyp

Based on https://github.com/joyent/node/tree/master/test/addons/hello-world

  • cd /tmp/
  • nano test.js
  • nano binding.cc
  • nano binding.gyp
  • node-gyp configure #The configure step looks for the binding.gyp file in the current directory
  • node-gyp build # gave an error building !

Based on https://github.com/rvagg/node-addon-examples

  • nano binding.gyp

{
  "targets": [
    {
      "target_name": "hello",
      "sources": [ "hello.cc" ]
    }
  ]
}
  • nano hello.cc

   1 #include <node.h>
   2 #include <v8.h>
   3 
   4 using namespace v8;
   5 
   6 Handle<Value> Method(const Arguments& args) {
   7   HandleScope scope;
   8   return scope.Close(String::New("world"));
   9 }
  10 
  11 void init(Handle<Object> exports) {
  12   exports->Set(String::NewSymbol("hello"),
  13       FunctionTemplate::New(Method)->GetFunction());
  14 }
  15 
  16 NODE_MODULE(hello, init)
  • nano hello.js

   1 var addon = require('./build/Release/hello');
   2 
   3 console.log(addon.hello()); // 'world'
   4 
  • node hello.js
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01