{"id":19220,"date":"2023-12-25T15:43:55","date_gmt":"2023-12-25T07:43:55","guid":{"rendered":"https:\/\/app.60day.cn\/appday\/?p=19220"},"modified":"2023-12-25T15:43:55","modified_gmt":"2023-12-25T07:43:55","slug":"ubuntunodejs%e5%bc%80%e5%8f%91%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a1%b9%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/app.60day.cn\/appday\/kaifaexe\/19220\/","title":{"rendered":"ubuntunodejs\u5f00\u53d1\u6ce8\u610f\u4e8b\u9879\u4ecb\u7ecd"},"content":{"rendered":"<p>Ubuntu\u662f\u4e00\u79cd\u57fa\u4e8eDebian\u7684Linux\u64cd\u4f5c\u7cfb\u7edf\uff0c\u662f\u5f00\u6e90\u8f6f\u4ef6\u7684\u4ee3\u8868\u4e4b\u4e00\u3002Node.js\u662f\u4e00\u4e2a\u57fa\u4e8eChrome V8\u5f15\u64ce\u7684JavaScript\u8fd0\u884c\u65f6\u73af\u5883\uff0c\u7528\u4e8e\u6784\u5efa\u5feb\u901f\u3001\u53ef\u6269\u5c55\u7684\u7f51\u7edc\u5e94\u7528\u7a0b\u5e8f\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728Ubuntu\u4e0a\u8fdb\u884cNode.js\u5f00\u53d1\u3002<\/p>\n<p>\u5b89\u88c5Node.js<\/p>\n<p>\u5728Ubuntu\u4e0a\u5b89\u88c5Node.js\u975e\u5e38<a href=\"https:\/\/exe.yimenapp.com\/tool-3439.html\">phpwamp\u6253\u5305exe<\/a>\u7b80\u5355\uff0c\u53ea\u9700\u8981\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u5373\u53ef\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>sudo apt-get update<\/p>\n<p>sudo apt-get install nodejs<\/p>\n<p>&#8220;`<\/p>\n<p>\u6b64\u5916\uff0c\u8fd8\u9700\u8981\u5b89\u88c5npm\uff08Node.js\u7684\u5305\u7ba1\u7406\u5668\uff09\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>sudo apt-get install npm<\/p>\n<p>&#8220;`<\/p>\n<p>\u521b\u5efa\u4e00\u4e2aNode.js\u5e94\u7528\u7a0b\u5e8f<\/p>\n<p>\u5728Ubuntu\u4e0a\u521b\u5efa\u4e00\u4e2aNode.js\u5e94\u7528\u7a0b\u5e8f\u975e\u5e38\u7b80\u5355\u3002\u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u76ee\u5f55\uff0c\u5e76\u8fdb\u5165\u8be5\u76ee\u5f55\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>mkdir myapp<\/p>\n<p>cd myapp<\/p>\n<p>&#8220;`<\/p>\n<p>\u7136\u540e\uff0c\u4f7f\u7528npm\u521d\u59cb\u5316\u9879\u76ee\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>npm init<\/p>\n<p>&#8220;`<\/p>\n<p>\u8be5\u547d\u4ee4\u5c06\u5f15\u5bfc\u60a8\u5b8c\u6210\u521b\u5efapackage.json\u6587\u4ef6\u7684\u8fc7\u7a0b\uff0c\u8be5\u6587\u4ef6\u5305\u542b\u5e94\u7528\u7a0b\u5e8f\u7684\u5143\u6570\u636e\u548c\u4f9d\u8d56\u9879\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aapp.js\u7684\u6587\u4ef6\uff0c\u5e76\u5728\u5176\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>const http = require(&#8216;http&#8217;);<\/p>\n<p>const hostname = &#8216;127.0.0.1&#8217;;<\/p>\n<p>const port = 3000;<\/p>\n<p>const server = http.createServer((req, res) =&gt; {<\/p>\n<p>  res.statusCode = 200;<\/p>\n<p>  res.setHeader(&#8216;Content-Type&#8217;, &#8216;text\/plain&#8217;);<\/p>\n<p>  res.end(&#8216;Hello World\\n&#8217;);<\/p>\n<p>});<\/p>\n<p>server.listen(port, hostname, () =&gt; {<\/p>\n<p>  console.log(`Server running at http:\/\/${hostname}:${port}\/`);<\/p>\n<p>});<\/p>\n<p>&#8220;`<\/p>\n<p>\u8be5\u4ee3\u7801\u521b\u5efa\u4e86\u4e00\u4e2aHTTP\u670d\u52a1\u5668\uff0c\u5e76\u5728\u7aef\u53e33000\u4e0a\u4fa6\u542c\u8bf7\u6c42\u3002\u5f53\u670d\u52a1\u5668\u6536\u5230\u8bf7\u6c42\u65f6\uff0c\u5b83\u5c06\u8fd4\u56de\u201cHello World\u201d\u3002<\/p>\n<p>\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f<\/p>\n<p>\u8981\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f\uff0c\u8bf7\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>node app.js<\/p>\n<p>&#8220;`<\/p>\n<p>\u60a8\u5e94\u8be5\u4f1a\u770b\u5230\u4ee5\u4e0b\u8f93\u51fa\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>Server running at http:\/\/127.0.0.1:3000\/<\/p>\n<p>&#8220;`<\/p>\n<p>\u73b0<a href=\"https:\/\/exe.yimenapp.com\/tool-642.html\">\u591a\u4e2aexe\u6587\u4ef6\u7ed1\u6210\u4e00\u4e2aexe<\/a>\u5728\uff0c\u60a8\u53ef\u4ee5\u5728Web\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00http:\/\/127.0.0.1:3000\/\uff0c\u5e76\u5e94\u8be5\u770b\u5230\u201cHello World\u201d\u6d88\u606f\u3002<\/p>\n<p>\u5b89\u88c5Express\u6846\u67b6<\/p>\n<p>Express\u662f<\/p>\n<p><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i.cdn.yimenapp.com\/2023-03\/28\/13\/01907526144.jpg\" \/><\/figure>\n<\/p>\n<p>\u4e00\u4e2a\u6d41\u884c\u7684Node.js Web\u5e94\u7528\u7a0b\u5e8f\u6846\u67b6\uff0c\u5b83\u53ef\u4ee5\u5e2e\u52a9\u60a8\u66f4\u8f7b\u677e\u5730\u6784\u5efaWeb\u5e94\u7528\u7a0b\u5e8f\u3002\u8981\u5b89\u88c5Express\uff0c\u8bf7\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>npm install express &#8211;save<\/p>\n<p>&#8220;`<\/p>\n<p>\u521b\u5efa\u4e00\u4e2aExpress\u5e94\u7528\u7a0b\u5e8f<\/p>\n<p>\u521b\u5efa\u4e00\u4e2aExpress\u5e94\u7528\u7a0b\u5e8f\u4e0e\u521b\u5efa\u4e00\u4e2aNode.js\u5e94\u7528\u7a0b\u5e8f\u7c7b\u4f3c\u3002\u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u76ee\u5f55\uff0c\u5e76\u8fdb\u5165\u8be5\u76ee\u5f55\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>mkdir myapp<\/p>\n<p>cd myapp<\/p>\n<p>&#8220;`<\/p>\n<p>\u7136\u540e\uff0c\u4f7f\u7528npm\u521d\u59cb\u5316\u9879\u76ee\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>npm init<\/p>\n<p>&#8220;`<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u5b89\u88c5Express\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>npm install express &#8211;save<\/p>\n<p>&#8220;`<\/p>\n<p>\u7136\u540e\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aapp.js\u7684\u6587\u4ef6\uff0c\u5e76\u5728\u5176\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>const express = require(&#8216;express&#8217;);<\/p>\n<p>const app = express();<\/p>\n<p>app.get(&#8216;\/&#8217;, (req, res) =&gt; {<\/p>\n<p>  res.send(&#8216;Hello World!&#8217;);<\/p>\n<p>});<\/p>\n<p>app.listen(3000, () =&gt; {<\/p>\n<p>  console.log(&#8216;Example app listening on port 3000!&#8217;);<\/p>\n<p>});<\/p>\n<p>&#8220;`<\/p>\n<p>\u8be5\u4ee3\u7801\u521b\u5efa\u4e86\u4e00\u4e2aExpress\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u5728\u7aef\u53e33000\u4e0a\u4fa6\u542c\u8bf7\u6c42\u3002\u5f53\u670d\u52a1\u5668\u6536\u5230\u8bf7\u6c42\u65f6\uff0c\u5b83\u5c06\u8fd4\u56de\u201cHello World\u201d\u3002<\/p>\n<p>\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f<\/p>\n<p>\u8981\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f\uff0c\u8bf7\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>node app.js<\/p>\n<p>&#8220;`<\/p>\n<p>\u60a8\u5e94\u8be5\u4f1a\u770b\u5230\u4ee5\u4e0b\u8f93\u51fa\uff1a<\/p>\n<p>&#8220;`<\/p>\n<p>Example app listening on port 3000!<\/p>\n<p>&#8220;`<\/p>\n<p>\u73b0\u5728\uff0c\u60a8\u53ef\u4ee5\u5728Web\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00http:\/\/localhost:3000\/\uff0c\u5e76\u5e94\u8be5\u770b\u5230\u201cHello World\uff01\u201d\u6d88\u606f\u3002<\/p>\n<p>\u603b\u7ed3<\/p>\n<p>\u5728Ubuntu\u4e0a\u8fdb\u884cNode.js\u5f00\u53d1\u975e\u5e38\u7b80\u5355\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528npm\u5b89\u88c5\u5404\u79cd\u5305\uff0c\u4f8b\u5982Express\u6846\u67b6\uff0c\u4ee5\u5e2e\u52a9\u60a8\u66f4\u8f7b\u677e\u5730\u6784\u5efaWeb\u5e94\u7528\u7a0b\u5e8f\u3002\u5982\u679c\u60a8\u662f\u4e00\u4e2a\u65b0\u624b\uff0c\u5efa\u8bae\u60a8\u4eceNode.js\u57fa\u7840\u77e5\u8bc6\u5f00\u59cb\uff0c\u5e76\u9010\u6b65\u5b66\u4e60\u66f4\u9ad8\u7ea7\u7684\u4e3b\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ubuntu\u662f\u4e00\u79cd\u57fa\u4e8eDebian\u7684Linux\u64cd\u4f5c\u7cfb\u7edf\uff0c\u662f\u5f00\u6e90\u8f6f\u4ef6\u7684\u4ee3\u8868\u4e4b\u4e00\u3002Node.js\u662f\u4e00\u4e2a\u57fa\u4e8eChrome V8\u5f15\u64ce\u7684JavaScript\u8fd0\u884c\u65f6\u73af\u5883\uff0c\u7528\u4e8e\u6784\u5efa\u5feb\u901f\u3001\u53ef\u6269\u5c55\u7684\u7f51\u7edc\u5e94\u7528\u7a0b\u5e8f\u3002\u672c\u6587<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[25000,429,1890,84,25001],"topic":[],"class_list":["post-19220","post","type-post","status-publish","format-standard","hentry","category-kaifaexe","tag-web","tag-429","tag-1890","tag-84","tag-exe"],"_links":{"self":[{"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/posts\/19220","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/comments?post=19220"}],"version-history":[{"count":1,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/posts\/19220\/revisions"}],"predecessor-version":[{"id":19285,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/posts\/19220\/revisions\/19285"}],"wp:attachment":[{"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/media?parent=19220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/categories?post=19220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/tags?post=19220"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/app.60day.cn\/appday\/wp-json\/wp\/v2\/topic?post=19220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}