- Learning Node.js for .NET Developers
- Harry Cummings
- 229字
- 2021-07-02 16:29:04
Installing and running Node.js
To install Node.js, visit https://nodejs.org, and download and run the installer package for the currently recommended version. The examples in this book are based on Node.js v6, released in April 2016 and supported through to April 2018.
After installation, open up a console window (run command prompt on Windows, or terminal on Mac) and type node
.
This opens the Node.js REPL, which works like the JavaScript console in browsers. Try typing in a few commands and see the output:
> function square(x) { return x*x; } undefined > square(42) 1764 > new Date() 2016-05-02T16:08:41.915Z > var foo = { bar: 'baz' } undefined > typeof foo 'object' > foo.bar 'baz'
Now let's make use of one of the Node.js-specific APIs to create an HTTP server. Type the following commands into the REPL (the output of each command is omitted from the listing below for brevity):
> var listener = function(request, response) { response.end('Hello World!') } > require('http').createServer(listener).listen(3000)
Now try visiting http://localhost:3000
in your browser. Congratulations! You have written your first web server, in just two lines of code. The first line defines a callback function for handling HTTP requests and returning a response. The second line sets up a new server that accepts HTTP requests on port 3000 and invokes our callback function for each request.
You can exit the Node.js REPL by typing process.exit()
.
- Python數據分析入門與實戰
- Java FX應用開發教程
- Architecting the Industrial Internet
- 跟小海龜學Python
- 21天學通C++(第6版)
- Unreal Engine 4 Shaders and Effects Cookbook
- C++對象模型詳解
- C++反匯編與逆向分析技術揭秘(第2版)
- Software-Defined Networking with OpenFlow(Second Edition)
- 例解Python:Python編程快速入門踐行指南
- Oracle SOA Suite 12c Administrator's Guide
- Java服務端研發知識圖譜
- Developer,Advocate!
- 測試工程師Python開發實戰
- C/C++語言程序開發參考手冊