Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world.javascript
Node所針對的應用程序有一個專門的簡稱:DIRT。它表示數據密集型實時(data-intensive real-time)程序。 由於Node自身在I/O上很是輕量,它善於將數據從一個管道混排或代理到另外一個管道上,這能在處理大量請求時持有不少開放的鏈接,而且只佔用一小部份內存,它的設計目標是保證相應能力,更瀏覽器同樣java
一個簡單的http服務器的實現node
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}/`); });
一個簡單的數據流示例:npm
let stream = fs.createReadStream('./resource.json') stream.on('data', (chunk) => ({ console.log(chunk) })) stream.on('end', () = ({ console.log('finished') }))
進擊Node.js基礎(一)json
nodejs實戰服務器