Getting Started Guide - Node.js
文章推薦指數: 80 %
Once we have installed Node.js, let's build our first web server. Create a file named app.js containing the following contents: ... Now, run your web server using ... Docs ES6andbeyond v16.17.1APILTS v18.9.1API Guides Dependencies HowdoIstartwithNode.jsafterIinstalledit?OncewehaveinstalledNode.js,let'sbuildourfirstwebserver. Createafilenamedapp.jscontainingthefollowingcontents: consthttp=require('http'); consthostname='127.0.0.1'; constport=3000; constserver=http.createServer((req,res)=>{ res.statusCode=200; res.setHeader('Content-Type','text/plain'); res.end('HelloWorld'); }); server.listen(port,hostname,()=>{ console.log(`Serverrunningathttp://${hostname}:${port}/`); }); Now,runyourwebserverusingnodeapp.js.Visithttp://localhost:3000and youwillseeamessagesaying"HelloWorld". RefertotheIntroductiontoNode.jsforamore comprehensiveguidetogettingstartedwithNode.js. ↑Scrolltotop
延伸文章資訊
- 1How To Write and Run Your First Program in Node.js
How To Write and Run Your First Program in Node.js · Step 1 — Outputting to the Console · Step 2 ...
- 2Step By Step Building Your First Node.JS Project - Medium
Step By Step Building Your First Node.JS Project. Node.js is becoming one of the most important t...
- 3Getting Started Guide - Node.js
Once we have installed Node.js, let's build our first web server. Create a file named app.js cont...
- 4Node.js - First Application - Tutorialspoint
Creating Node.js Application · Step 1 - Import Required Module · Step 2 - Create Server · Step 3 ...
- 5Node.js First Example - javaTpoint
A node.js web application contains the following three parts: ... Follow these steps: ... var htt...