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

其他

nodejs review-04的更多相关文章

  1. nodejs复习04

    TCP/UDP网络应用 创建TCP服务器客户端 socket套接字对象实例,是对TCP协议的一个基本封装接口 clientt套接字对象实例 //server.js var net = require( ...

  2. nodeJs学习-04 POST数据请求,分段发送,分段接收

    const http = require("http"); const querystring= require('querystring'); http.createServer ...

  3. 在虚拟机中安装Ubuntu Server 15.04

    学Linux,上红联! 红联Linux门户|Linux通用技术|Linux发行版技术|Linux企业应用|Linux实验室|红联Linux论坛 Linux系统教程 Linux入门 Linux管理 Li ...

  4. NodeJS错误处理最佳实践

    NodeJS的错误处理让人痛苦,在很长的一段时间里,大量的错误被放任不管.但是要想建立一个健壮的Node.js程序就必须正确的处理这些错误,而且这并不难学.如果你实在没有耐心,那就直接绕过长篇大论跳到 ...

  5. 如何提高NodeJS程序的运行的稳定性

    如何提高NodeJS程序运行的稳定性 我们常通过node app.js方式运行nodejs程序,但总有一些异常或错误导致程序运行停止退出.如何保证node程序的稳定运行? 下面是一些可以考虑的方案: ...

  6. Ubuntu Server16.04 安装Odoo11

    odoo11采用了python3实现的. 1.sudo adduser odoo   //新建一个用户odoo 2.给odoo 用户root 权限 visudo   //使用visudo 编辑 /et ...

  7. [Java 教程 04] Java基础语法

    在上一篇文章中我们已经运行了个简单的java程序,但是没有给大家讲解代码部分的内容与含义.学习,我们要做到知其然而知其所以然,所以本篇文章我们就来讲解java程序的基本语法,学完这篇文章你再回头看上篇 ...

  8. qnx gpio

    in order to set gpio in qnx, you can use msmgpiotool # msmgpiotool gpiotool usage: gpiotool <comm ...

  9. [Intel Edison开发板] 04、Edison开发基于nodejs和redis的服务器搭建

    一.前言 intel-iot-examples-datastore 是Intel提供用于所有Edison开发板联网存储DEMO所需要的服务器工程.该工程是基于nodejs和redis写成的一个简单的工 ...

  10. Angularjs学习---angularjs环境搭建,ubuntu 12.04下安装nodejs、npm和karma

    1.下载angularjs 进入其官网下载:https://angularjs.org/‎,建议下载最新版的:https://ajax.googleapis.com/ajax/libs/angular ...

随机推荐

  1. druid数据库密码加密程序编写

    第一步:引入 druid-1.0.1.jar 架包 第二步: 编写程序 package nihao; import com.alibaba.druid.filter.config.ConfigTool ...

  2. Google 地图 API V3 之控件

    Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...

  3. (转)Javascript本地存储小结

    转自:https://i.cnblogs.com/EditPosts.aspx?opt=1 以下是原文: 1. 各种存储方案的简单对比 Cookies:浏览器均支持,容量为4KB UserData:仅 ...

  4. input placeholder兼容ie10以下

    代码如下: ,) < ) { $('input[placeholder]').each(function(){ var input = $(this); $(input).val(input.a ...

  5. 【GoLang】golang 中 defer 参数的蹊跷

    参考资料: http://studygolang.com/articles/7994--Defer函数调用参数的求值 golang的闭包和普通函数调用区别:http://studygolang.com ...

  6. Servlet 之 GenericServlet

    我们都知道javaweb中servlet的三大组件 servlet filter listener 实现动态资源的  是可以继承  Servlet接口,或者集成GenericServlet .Http ...

  7. nginx笔记资料

    通配 hash 表 ngx_hash_init 实现注释:http://blog.csdn.net/gsnumen/article/details/7817396 ngx_hash_init之后的结构 ...

  8. 关于awk的逗号问题

    对于awk逗号的问题,我昨天看的一本书有提过: <Linux就是这个范儿>挺好的书,大家可以看看~~~~ 测试过,总结如下(不知道总结有没有错,欢迎大家吐槽,欢迎大家吐槽,吐槽,吐槽... ...

  9. .NET 反射概述

    反射      反射提供了封装程序集.模块和类型的对象(Type 类型).可以使用反射动态创建类型的实例,将类型绑定到现有对象,或从现有对象获取类型并调用其方法或访问其字段和属性.如果代码中使用了属性 ...

  10. LeetCode 118 Pascal's Triangle

    Problem: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows  ...