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开发网站相关推荐
- node.js编写网页_为Node.js编写可扩展架构
node.js编写网页 by Zafar Saleem 通过Zafar Saleem 为Node.js编写可扩展架构 (Writing Scalable Architecture For Nodejs ...
- node.js中模块_在Node.js中需要模块:您需要知道的一切
node.js中模块 by Samer Buna 通过Samer Buna 在Node.js中需要模块:您需要知道的一切 (Requiring modules in Node.js: Everythi ...
- js list操作_使用 Node.js 实现一个命令行 todo-list(1)- 基本功能
功能介绍 为了熟悉 Node.js,使用 Node.js 制作一个命令行小工具,项目仓库:https://github.com/FuZhouJohn/node-todo,先来介绍一下功能: 添加任务: ...
- nw.js 调用驱动程序_使用NW.js创建照片发现应用程序(第2部分)
nw.js 调用驱动程序 NW.js (formerly known as Node Webkit) is a framework for creating cross-platform deskto ...
- node开启子线程_真Node多线程
本文测试使用环境: 系统:macOS Mojave 10.14.2 CPU:4 核 2.3 GHz Node: 10.15.1 从 Node 线程说起 一般人理解 Node 是单线程的,所以 Node ...
- python开发一个自己的技术网站_手把手教你写网站:Python WEB开发技术实战
摘要:本文详细介绍了Python WEB开发的基础入门.以一个博客站点的开发为例讲解了基于Django框架开发WEB站点的全过程.通过本文的学习可以快速掌握基于Django的Python WEB的开发 ...
- js input 自动换行_深入Slate.js - 拯救 ContentEditble
我们是钉钉的文档协同团队,我们在做一些很有意义的事情,其中之一就是自研的文字编辑器.为了把自研文字编辑器做好,我们调研了开源社区各种优秀编辑器,Slate.js 是其中之一(实际上,自研文字编辑器前, ...
- react项目开发步骤_成为专业React开发人员的31个步骤
react项目开发步骤 我为达到可雇用水平而进行的每个项目和课程. (Every single project and course I took to reach a hireable level. ...
- python前端开发招聘_【天津前端开发招聘_最新天津前端开发招聘信息】-前程无忧...
天津卓众信息技术有限公司天津-西青区0.6-1万/月11-23 学历要求:本科|工作经验:3-4年|公司性质:民营公司|公司规模:少于50人 1.根据产品设计实现产品的页面交互和数据逻辑展示,负责前端 ...
- web开发指南_成为专业Web开发人员的实用指南
web开发指南 This article is meant to serve as a practical guide to becoming a professional web developer ...
最新文章
- Codeforces 458C - Elections
- 网络安全09_部署Windows XP、Windows Server 2003、Windows server 2008、Windows 7 每个虚拟机各两台(2)
- Python入门之数据类型
- C#并行编程(4):基于任务的并行
- shell脚本_Shell脚本
- java面试题23 牛客ArrayLists和LinkedList的区别,下述说法正确的有?
- java 如何循环执行一个对象_Java基础:如何定义好一个方法和进行方法重载
- Java JDBC篇1——初识JDBC
- 香蕉派,蜘蛛侠手臂和USO世界
- HTML+CSS零基础学习笔记(二)
- EXE文件反编译工具下载
- robotium3.6与4.0以后的区别
- DirectX 下载地址
- 计算机自检后反复重启 主引导,电脑开机老是重复重启的解决方法
- 安装Ofiice2016 错误提示“检查您的internet连接是否工作正常”等
- 人工智能技术助力民族语言保护大有可为
- 【渝粤题库】广东开放大学 建筑施工技术 形成性考核
- C++基础(1)- 声明(前向声明 Forward Declaration)与定义
- 必应每日一图直接获取及接口
- 金山词霸字典转换工具
热门文章
- python连接mysql代码_Python3连接MySQL(pymysql)转账代码
- es 删除重复数据_怎么标识并删除SPSS数据库里的“重复个案”?
- android 电话号码标记,强化电话标记功能 360手机卫士3.0安卓版体验
- Go实现简单的RESTful_API
- 八年开发程序员浅析SpringBoot 之 Shiro 与 Redis 多级缓存问题
- Python之路(第二篇):Python基本数据类型字符串(一)
- vim 高亮显示php代码
- 将Java应用程序本地编译为EXE的几种方法
- Asp.net基础概念之 事件
- 设计模式----Adapter(适配器)