nodejs文件服务器
发布日期:2019-09-12 20:55 | 文章来源:网络
香港服务器
香港CN2服务器、企业级CN2 GIA双程专线高速回国T3机房香港、美国、韩国、海外物理服务器热销中!
本文尝试使用nodejs搭建一个文件服务器。
首先在官方下载node环境并安装:nodejs.org/en/download/
安装后node被加入到系统环境变量中。
>node--version
>v12.14.1
1consthttp=require;2constPath=require;3constfs=require;45varserver=http.createServer{6letcurrUrl=decodeURIComponent;7constfileName=Path.resolve;8constextName=Path.extname.substr;910if){//判断本地文件是否存在11varmineTypeMap={12html:'text/html;charset=utf-8',13htm:'text/html;charset=utf-8',14xml:"text/xml;charset=utf-8",15png:"image/png",16jpg:"image/jpeg",17jpeg:"image/jpeg",18gif:"image/gif",19css:"text/css;charset=utf-8",20txt:"text/plain;charset=utf-8",21mp3:"audio/mpeg",22mp4:"video/mp4",23ico:"image/x-icon",24tif:"image/tiff",25svg:"image/svg+xml",26zip:"application/zip",27ttf:"font/ttf",28woff:"font/woff",29woff2:"font/woff2",30}31if{32res.setHeader;33}34varstream=fs.createReadStream;35stream.pipe;36}37})38server.listen{39console.log;40});
文件目录:
Tags:香港服务器,nodejs文件服务器
版权声明:本站文章来源标注为YINGSOO的内容版权均为本站所有,欢迎引用、转载,请保持原文完整并注明来源及原文链接。禁止复制或仿造本网站,禁止在非www.yingsoo.com所属的服务器上建立镜像,否则将依法追究法律责任。本站部分内容来源于网友推荐、互联网收集整理而来,仅供学习参考,不代表本站立场,如有内容涉嫌侵权,请联系alex-e#qq.com处理。
相关文章