6.27. Using Node.js modules

Porting Node.js modules is a very simple process.

Add USES=node to the port's Makefile. The framework will install the relevant files in the right places. It create the packaging list automatically.

If a port need to install headers or build extension, instructions on how to select it are given in the USES=node part of Chapter 15, Using USES Macros.

Ports that install files under NODE_MODULEDIR must use the node- name prefix.

Table 6.40. Useful Variables for Porting Node.js Modules
VariableValue
NODE_MODULEDIRThe directory, where the Node.js module is installed. Default ${PREFIX}/${NODE_LIBDIR}/${PORTNAME}
NODE_SCRIPTSList of Node.js scripts, located in ${NODE_MODULEDIR}/${NODE_SCRIPTSDIR}
NODE_SCRIPTSDIRRelative paths, where scripts are located. Default bin/
NODE_MAN3List of man pages
NODE_EXCLUDEDIRSList of additional directories to exclude

Example 6.20. Example Makefile for Node.js Module
PORTNAME=       underscore
PORTVERSION=    1.8.3
CATEGORIES=     devel node
MASTER_SITES=   NPM

MAINTAINER=     ports@FreeBSD.org
COMMENT=        JavaScript's functional programming helper library

USES=   node tar:tgz

.include <bsd.port.mk>

Example 6.21. Example Makefile with Node.js scripts
PORTNAME=       coffee-script
PORTVERSION=    1.9.3
CATEGORIES=     lang node
MASTER_SITES=   NPM

MAINTAINER=     ports@FreeBSD.org
COMMENT=        Interpreter and compiler for the CoffeeScript language

RUN_DEPENDS=    node-underscore>=1.8.3:devel/node-underscore

USES=   node tar:tgz

NODE_SCRIPTS=   cake coffee

.include <bsd.port.mk>

Note:

The framework automatically creates symlinks in ${PREFIX}/bin.

Example 6.22. Example Makefile with NODE_EXCLUDEDIRS
PORTNAME=       hooker
PORTVERSION=    0.2.3
CATEGORIES=     devel node
MASTER_SITES=   NPM

MAINTAINER=     ports@FreeBSD.org
COMMENT=        Useful debugging library for Node.js

USES=   node tar:tgz

NODE_EXCLUDEDIRS=    dist/

.include <bsd.port.mk>

Important:

For NODE_SCRIPSDIR, and NODE_EXCLUDEDIRS each name needs trailing slash at end.

Example 6.23. Wrong NODE_EXCLUDEDIRS in Makefile
NODE_EXCLUDEDIRS=    foo bar

Example 6.24. Correct NODE_EXCLUDEDIRS in Makefile
NODE_EXCLUDEDIRS=    foo/ bar/

All FreeBSD documents are available for download at http://ftp.FreeBSD.org/pub/FreeBSD/doc/

Questions that are not answered by the documentation may be sent to <freebsd-questions@FreeBSD.org>.
Send questions about this document to <freebsd-doc@FreeBSD.org>.