javascript
node js 开发网站_使用Node JS开发网站
node js 開發網站
You will have your own fully functional website running on "localhost" after going through this article.
閱讀完本文后,您將在“ localhost”上運行自己的功能齊全的網站 。
Basic knowledge of JavaScript and HTML is a prerequisite.
必須具備JavaScript和HTML的基礎知識。
Here are the source codes of the webpages...
這是網頁的源代碼...
JS file (a.js)
JS檔案(a.js)
var http = require('http');var fs = require('fs');function notfoundfunc(response) {response.writeHead(404, {"Context-Type": "text/plain"});response.write("page not found");response.end(); }function myfunc(request, response) {if (request.method == 'GET' && request.url == '/') {response.writeHead(200, {"Context-Type": "text/html"});fs.createReadStream("./index.html").pipe(response);} else if (request.method == 'GET' && request.url == '/about') {response.writeHead(200, {"Context-Type": "text/html"});fs.createReadStream("./about.html").pipe(response);} else {notfoundfunc(response);} }http.createServer(myfunc).listen(3500); console.log("server made");index.html
index.html
<html><body>welcome to my website.</body></html>about.html
about.html
<html><body>developed by mansha lamba.</body></html>Output screenshot 1
輸出屏幕截圖1
Output screenshot 2
輸出屏幕截圖2
Output screenshot 3
輸出屏幕截圖3
Explanation of the code:
代碼說明:
The source code is very easy to understand.
源代碼非常容易理解。
Please note that instead of giving a plain text output like in my previous article here I have used HTML files. For that, another inbuilt module in NODE JS is used i.e. fs.
請注意,不是使用純文本輸出,而是使用HTML文件。 為此,使用了NODE JS中的另一個內置模塊,即fs。
Rest of the code is self-explanatory.
其余代碼是不言自明的。
翻譯自: https://www.includehelp.com/node-js/developing-a-website.aspx
node js 開發網站
總結
以上是生活随笔為你收集整理的node js 开发网站_使用Node JS开发网站的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: bba70_BBA的完整形式是什么?
- 下一篇: Python | 使用__del __(