Merge branch 'v0.4'
[platform/upstream/nodejs.git] / doc / api / globals.markdown
1 ## Global Objects
2
3 These object are available in all modules. Some of these objects aren't
4 actually in the global scope but in the module scope - this will be noted.
5
6 ### global
7
8 The global namespace object.
9
10 In browsers, the top-level scope is the global scope. That means that in
11 browsers if you're in the global scope `var something` will define a global
12 variable. In Node this is different. The top-level scope is not the global
13 scope; `var something` inside a Node module will be local to that module.
14
15 ### process
16
17 The process object. See the [process object](process.html#process) section.
18
19 ### console
20
21 Used to print to stdout and stderr. See the [stdio](stdio.html) section.
22
23
24 ### require()
25
26 To require modules. See the [Modules](modules.html#modules) section.
27 `require` isn't actually a global but rather local to each module.
28
29
30 ### require.resolve()
31
32 Use the internal `require()` machinery to look up the location of a module,
33 but rather than loading the module, just return the resolved filename.
34
35 ### require.paths
36
37 An array of search paths for `require()`.  This array can be modified to add
38 custom paths.
39
40 Example: add a new path to the beginning of the search list
41
42     require.paths.unshift('/usr/local/node');
43
44
45 ### __filename
46
47 The filename of the script being executed.  This is the absolute path, and not necessarily
48 the same filename passed in as a command line argument.
49
50 Example: running `node example.js` from `/Users/mjr`
51
52     console.log(__filename);
53     // /Users/mjr/example.js
54
55 `__filename` isn't actually a global but rather local to each module.
56
57 ### __dirname
58
59 The dirname of the script being executed.
60
61 Example: running `node example.js` from `/Users/mjr`
62
63     console.log(__dirname);
64     // /Users/mjr
65
66 `__dirname` isn't actually a global but rather local to each module.
67
68
69 ### module
70
71 A reference to the current module. In particular
72 `module.exports` is the same as the `exports` object. See `src/node.js`
73 for more information.
74 `module` isn't actually a global but rather local to each module.
75
76 ### setTimeout(cb, ms)
77 ### clearTimeout(t)
78 ### setInterval(cb, ms)
79 ### clearInterval(t)
80
81 The timer functions are global variables. See the [timers](timers.html) section.