nodejs review-04
2024-08-26 00:42:54
79 Secure your projects with HTTPS Express
- 生成
SSL
证书
openssl genrsa -out privkey.pem 1023
openssl req -new -key privkey.pem -out certreq.csr
openssl x509 -req -days 3650 -in certreq.csr -signkey privkey.pem -out newcert.pem
- 基本服务器
var fs = require('fs');
var https = require('https');
var express = require('express');
var app = express();
var options = {
key: fs.readFileSync('privkey.pem').toString(),
cert: fs.readFileSync('newcert.pem').toString()
};
https.createServer(options, app).listen(8080);
app.get('*', function (req, res) {
res.end('START HTTPS');
});
81 Develop for multiple platforms
- 不同平台的文件路径连接符号
var path = require('path');
path.sep;
- 判断平台
process.platform
//darwin, win32
83 Run command line scripts Unix like
- 运行
node
脚本
//hello
#!/usr/bin/env node // 正常情况下可以改成#!usr/local/bin/node
console.log('hello');
//权限
chmod 755 hello //0755 = User:rwx Group:r-x World:r-x
//运行
./hello
86 Understand the basics of stdin stdout
- 输入输出流
//sdin, stdout, stderr
//将输入字符串md5加密后输出
var crypto = require('crypto');
process.stdout.write('> ');
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (data) {
if(data && data === 'q\n') {
process.stdin.pause();
} else if(data) {
var h = crypto.createHash('md5');
var s = h.update(data).digest('hex');
console.log(s);
process.stdout.write('> ');
}
});
87 Launch processes with the exec function
child_process.exec
var exec = require('child_process').exec;
if(process.argv.length !== 3) {
console.log('not sopport');
process.exit(-1);
}
var cmd = process.platform === 'win32' ? 'type' : 'cat'; //注意不同平台
exec(cmd + ' ' + process.argv[2], function (err, stdout, stderr) {
if(err) return console.log(err);
console.log(stdout.toString('utf8'));
console.log(stderr.toString('utf8'));
});
其他
- 使用bcrypt-nodejs进行加密对比
- 使用node-jsonwebtoken来制造,验证
token
最新文章
- struts2中Ajax校验
- ibatis 和 mybatis
- python yield from用法
- 【转】JavaScript 经常忽略的 7 个基础知识点
- hashMap的数据结构
- timestamp 类型的索引
- cf429B dp递推
- Qt之模拟时钟
- oracle DML错误日志(笔记)
- Win8.1安装VirtualSVN Server发生service visualSVN Server failed to start解决办法
- hdu 2037 今年暑假不AC (java)
- 多台服务之间共享Session
- PhpMyAdmin隐藏数据库设置同前缀失效的问题
- 使用Spring Boot快速构建基于SQLite数据源的应用
- poj 1064 Cable master 判断一个解是否可行 浮点数二分
- python----re正则模块详解
- 剑指Offer_编程题_17
- 掌握闭包closure (含义及优缺点)
- Android 软件退出系统方法重写
- Mongodb 无法启动 windows Mongodb 无法启动 couldn't connect to server