Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 90 lines (62 sloc) 2.765 kB
2db9009 @felixge Proper titles
authored
1 % Felix's Node.js Package Guide
ad45db1 @felixge Initial import of iPad Notes
authored
2
5a4946f @felixge Mark incomplete guides
authored
3 # IMPORTANT: This guide is not ready to yet, please go away.
4
b22fdbb @felixge 80 character line length
authored
5 There is no official way that dictates how you may structure and publish your
6 node.js packages. This guide aims to provide you with an oppinionated set of
7 conventions based on popular choices within the node.js community.
ad45db1 @felixge Initial import of iPad Notes
authored
8
9 ## Related Guides
10
11 * Felix's Node.js Beginner's Guide - If you are new to node.js
12 * Felix's Node.js Style Guide^ - If you want your code to look nice
13 * Felix's Node.js Object Oriented Programming Guide^ - If you care about well-structured software
14 * Felix's Node.js Test Driven Development Guide^ - If you want to use test driven development
15
16 ## Directory Structure
17
b22fdbb @felixge 80 character line length
authored
18 You can basically structure your packages any way you want, but here is a good
19 set of conventions that will allow you to do so consistently.
ad45db1 @felixge Initial import of iPad Notes
authored
20
b22fdbb @felixge 80 character line length
authored
21 Let's assume you want to create a simple package called '' that provides you
22 with basic mathematical functions concerning 2D structures:
ad45db1 @felixge Initial import of iPad Notes
authored
23
24 package.json
25 node_modules/
26   geometry/
27     index.js
28     circle.js
29     point.js
30     square.js
31     triangle.js
32 test/
33   micro/
34     test-circle.js
35     test-square.js
36     test-point.js
37     test-triangle.js
38   integration/
39   system/
40
b22fdbb @felixge 80 character line length
authored
41 To explain: Your main package goes into the 'node_modules' folder, the same
42 place where npm will bundle any dependencies your package may have. Since node's
43 module system recognizes this folder, you can do `require('geometry/circle')`
44 from any JavaScript file within your module, without expicitely having to
45 provide the path for it.
ad45db1 @felixge Initial import of iPad Notes
authored
46
b22fdbb @felixge 80 character line length
authored
47 For more information on the contens of the 'test' folder, please visit my Test
48 Driven Development Guide^.
ad45db1 @felixge Initial import of iPad Notes
authored
49
50 ## 
51
52 ## Using git for version control
53
b22fdbb @felixge 80 character line length
authored
54 Most people in the node.js community use Git^ / GitHub^ to manage and publish
55 their source code. If you are using Git, you probably want to exclude your
56 dependencies from showing up in your git repository. In order to do so, create a
57 '.gitignore' file with the following content in your packages root directory:
ad45db1 @felixge Initial import of iPad Notes
authored
58
59 /node_modules/*
60 !/node_modules/geometry/*
61
b22fdbb @felixge 80 character line length
authored
62 This will ignore everything in your 'node_modules' folder, except your package
63 (which in this case is named 'geometry').
ad45db1 @felixge Initial import of iPad Notes
authored
64
65 ## Editor settings
66
b22fdbb @felixge 80 character line length
authored
67 You probably want to configure your editor to ignore anything except your main
68 module in the 'node_modules' folder when searching through files. Here are the
69 instructions on how to do so for a few choosen editors:
ad45db1 @felixge Initial import of iPad Notes
authored
70
71 ### Vim
72
73 ^todo
74
75 ### TextMate
76
77 ^todo
78
79 ## Publishing to npm
80
b22fdbb @felixge 80 character line length
authored
81 Npm^ is the de-facto package manager used by the node community, and the
82 Beginner's Guide^ includes instructions on how to install it.
ad45db1 @felixge Initial import of iPad Notes
authored
83
84 In order to publish a package, you need to create a user account like so:
85
86 npm adduser <your-username>
87 ^todo: Check if this is the correct syntax
88
89
Something went wrong with that request. Please try again.