生成证书
管理员权限打开cmd
Microsoft Windows [版本 10.0.16299.125]
(c) 2017 Microsoft Corporation。保留所有权利。
C:\WINDOWS\system32>openssl genrsa -out privatekey.pem 1024
Generating RSA private key, 1024 bit long modulus
............++++++
.................................++++++
e is 65537 (0x10001)
C:\WINDOWS\system32>openssl req -new -key privatekey.pem -out certrequest.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:js
Locality Name (eg, city) []:MJ
Organization Name (eg, company) [Internet Widgits Pty Ltd]:SV
Organizational Unit Name (eg, section) []:SW
Common Name (e.g. server FQDN or YOUR name) []:localhost
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:qweasdzxc
An optional company name []:ganmu
C:\WINDOWS\system32>openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certificate.pem
Signature ok
subject=/C=AU/ST=js/L=MJ/O=SV/OU=SW/CN=localhost
Getting Private key
C:\WINDOWS\system32>openssl pkcs12 -export -in certificate.pem -inkey privatekey.pem -out certificate.pfx
Enter Export Password:
Verifying - Enter Export Password:
C:\WINDOWS\system32>
https模块
var https = require('https');
var fs = require('fs');
var pk = fs.readFileSync("./certs/privatekey.pem");
var pc = fs.readFileSync("./certs/certificate.pem");
var opts = {
key:pk,
cert:pc
};
var server = https.createServer(opts, function(req, res) {
console.log(req.url);
if(req.url !== './favicon.ico') {
res.setHeader("contentType","text/plain");
res.write("hello");
res.end();
}
});
server.listen(443, "localhost", function() {
console.log('https server is listening on 443');
});
浏览器会拦截访问,提示该访问为不安全链接,因为证书无效。
var https = require('https'); var opts = { hostname:"npmjs.org", port:443, path:"/", method:"GET", agent:false }; opts.agent = new https.Agent(opts); var req = https.request(opts, function(res) { console.log(res.statusCode); console.log(JSON.stringify(res.headers)); res.setEncoding('utf8'); res.on('data', function(chunk) { console.log(chunk); }); }); req.on("error", function(err) { console.log(err); }) req.on("socket", function(socket) { socket.setTimeout(10*1000); socket.on("timeout", function() { req.abort(); }); }) req.end();
运行
F:\后台开发\node-server-test>node client.js
301
{
"server":"nginx/1.12.2",
"date":"Thu, 26 Apr 2018 16:36:16 GMT",
"content-type":"text/html",
"content-length":"185",
"connection":"close",
"location":"https://www.npmjs.com/"
}
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.12.2</center>
</body>
</html>
ES6中 export 和 export default 与 import使用的区别,使用 react native 代码详解,现在流行的前端框架,angular+ 主要使用 export 导出模块,react native 中使用 export default 导出模块,如今编辑器非常强大,安装插件会自动弹出模块名称,知道其导出怎么使用就可以了
最新版的 node 支持最新版 ECMAScript 几乎所有特性,但有一个特性却一直到现在都还没有支持,那就是从 ES2015 开始定义的模块化机制。而现在我们很多项目都是用 es6 的模块化规范来写代码的,包括 node 项目
nodejs 的 zlib 模块提供了资源压缩功能。例如在 http 传输过程中常用的 gzip,能大幅度减少网络传输流量,提高速度。本文将从下面几个方面介绍 zlib 模块和相关知识点:文件压缩 / 解压,HTTP 中的压缩/解,压缩算法:RLE
Node.js模块系统:为了让Node.js的文件相互调用,Node.js提供了一个简单的模块系统,Node.js应用程序的组成就是由模块组成基本部分,文件和模块是一一对应的。
nodejs 提供了os.platform()和os.type(),可以用来识别操作系统平台。推荐使用: os.platform(),平均负载是指:单位时间内,系统处于可运行状态和不可中断状态的平均进程数。它和 cpu 使用率没有直接关系。
模块化开发优点:模块化开发中,通常一个文件就是一个模块,有自己的作用域,只向外暴露特定的变量和函数,并且可以按需加载。依赖自动加载,按需加载。提高代码复用率,方便进行代码的管理,使得代码管理更加清晰、规范。
Javascript模块的写法-AMD, CMD, CommonJS和UMD。JavaScript中出现了一些非传统模块开发方式的规范 CommonJS的模块规范,AMD,CMD等。
例如在 ECMAScript 5 中引入的许多程序员首选的严格模式曾经是可选的,必须明确启用才行,同时它在 ES 模块中始终处于活动状态。因此,以下代码段在语法上可以解释为传统的 JavaScript 代码和 ES 模块
模块化主要是用来抽离公共代码,隔离作用域,避免变量冲突等。将一个复杂的系统分解为多个模块以方便编码。会讲述以下内容:CommonJS、AMD 及 核心原理实现、CMD 及 核心原理实现
Common这个英文单词的意思,相信大家都认识,我记得有一个词组common knowledge是常识的意思,那么CommonJS是不是也是类似于常识性的,大家都理解的意思呢?很明显不是,这个常识一点都不常识
内容以共享、参考、研究为目的,不存在任何商业目的。其版权属原作者所有,如有侵权或违规,请与小编联系!情况属实本人将予以删除!