Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
An introduction of NodeJS for Digital Arts and New Media MFA Program at UCSC
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.gitignore
001_serve.js
002_serve.js
005_favivon.js
006_mp3file.js
007_say.js
008_yousay.js
008b_yousay.js
009_express.js
010_osc.js
011_music.js
011b_music.js
012_bonus.js
README.md
package.json
plucky.js

README.md

Welcome DANM

This introduction by example to NodeJS is inteneded to remove the barriers and show some posibilities of using NodeJS in art creation.

Start

Node is an open source application that interperets and runs JavaScript code.

Node is a command line utility, which means you run it by opening a terminal on a machine which has node and typing something like this: node 001_serve.js This tells node to run and start executing the code in the file '001_serve.js' - to do this you must open terminal and be in the folder where a file like that exists. You may need an interoduction to the command line:

Getting your computer ready for this DANM.JOY

NPM and Node

Some of these examples use 'modules' of other code, they are included in the project by using this sort of syntax:

var exec = require('child_process').exec

The above example uses a module that is core to Node which means you do not need to install it to get it to work. Other modules you will need to install in your computer. You do this by using the 'npm' command. Please take a look at this introduction to NPM.

npm install node-osc

Will install the Node Open Sound Contol module so you can use the module (like in 010_osc.js)

var osc = require('node-osc');

001_serve.js

starts a web server. If you run 'node 001_serve.js'

002_serve.js

Using a module

var qs = require('querystring')

Add this line at line 6 in the file

console.log(qs.parse(url.parse(req.url).query))

005_favivon.js (woops)

This file shows going and getting a file and saving it on your computer.

006_mp3.js

You can download mp3s too. Try regular expressions from http://rubular.com/

I really like this "play" command line tool which is part of the SoX - Sound eXchange <- installers exist there for OS X, Windows and Linux. And for OS X you can use brew to isntall it: Install Homebrew

Then install SoX using homebrew

brew install sox

After you install SoX you can play an audio file from the command line:

play mp3file.mp3

Here is something that you can run to listen to random:

play -c1 -r 44k -t s8 /dev/urandom

(You can stop a running terminal command with a 'Conrtol + C'

If you do not want to do all of that you can make some sound on OS X using this command:

say stuff

But you will not be able to run some demos below.

007_say.js

This one uses the "exec" to run a command line program from node. OS X only - but you can run 'cmd' on Windows to open another terminal.-- I think.

008_yousay.js

OS X only,... This starts a web server and you can use a web browser to have your compy talk.

009_express.js

To really do a web application go take a look at the expressJS guide. There is a note to look at ~/Code/spell - but that is just for me when I was presenting.

010_osc.js

Open sound control is really cool - you can find a lot of cool apps that build clients for Open Sound Control. I have a cool iOS app that allows you to use a bunch of sensors on my iPhone to send data to this server. Cool stuff.

011 - 012

the baudio module (by substack) allows you to have a lot of fun with music with node. You will need SoX (above) to install the module:

npm install baudio

Take a look at this cool video of substack using baudio to get inspired

Something went wrong with that request. Please try again.