- Assertion Testing
- Buffer
- C/C++ Addons
- Child Processes
- Cluster
- Command Line Options
- Console
- Crypto
- Debugger
- DNS
- Domain
- Errors
- Events
- File System
- Globals
- HTTP
- HTTPS
- Modules
- Net
- OS
- Path
- Process
- Punycode
- Query Strings
- Readline
- REPL
- Stream
- String Decoder
- Timers
- TLS/SSL
- TTY
- UDP/Datagram
- URL
- Utilities
- V8
- VM
- ZLIB
Node.js v7.5.1-test20170201baf1e18b0c Documentation
Usage#
node [options] [v8 options] [script.js | -e "script"] [arguments]
Please see the Command Line Options document for information about different options and ways to run scripts with Node.js.
Example#
An example of a web server written with Node.js which responds with
'Hello World'
:
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
To run the server, put the code into a file called example.js
and execute
it with Node.js:
$ node example.js
Server running at http://127.0.0.1:3000/
All of the examples in the documentation can be run similarly.