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'));
});

其他

最新文章

  1. struts2中Ajax校验
  2. ibatis 和 mybatis
  3. python yield from用法
  4. 【转】JavaScript 经常忽略的 7 个基础知识点
  5. hashMap的数据结构
  6. timestamp 类型的索引
  7. cf429B dp递推
  8. Qt之模拟时钟
  9. oracle DML错误日志(笔记)
  10. Win8.1安装VirtualSVN Server发生service visualSVN Server failed to start解决办法
  11. hdu 2037 今年暑假不AC (java)
  12. 多台服务之间共享Session
  13. PhpMyAdmin隐藏数据库设置同前缀失效的问题
  14. 使用Spring Boot快速构建基于SQLite数据源的应用
  15. poj 1064 Cable master 判断一个解是否可行 浮点数二分
  16. python----re正则模块详解
  17. 剑指Offer_编程题_17
  18. 掌握闭包closure (含义及优缺点)
  19. Android 软件退出系统方法重写
  20. Mongodb 无法启动 windows Mongodb 无法启动 couldn't connect to server

热门文章

  1. IntelliJ IDEA 常用设置讲解
  2. Sql简单封装
  3. Java文件写入,换行
  4. DataTable的过滤需要的数据
  5. GIT本地配置和PUSH
  6. css清楚浮动的方法
  7. @Controller和@RestController的区别?
  8. 以空白符结尾的 alias
  9. 记录一下git 的常用命令
  10. Burpsuite+sqlmap批量扫描sql漏洞