Getting Started Guide - Node.js

文章推薦指數: 80 %
投票人數:10人

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



請為這篇文章評分?