nodejs review-04
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
nodejs review-04的更多相关文章
- nodejs复习04
TCP/UDP网络应用 创建TCP服务器客户端 socket套接字对象实例,是对TCP协议的一个基本封装接口 clientt套接字对象实例 //server.js var net = require( ...
- nodeJs学习-04 POST数据请求,分段发送,分段接收
const http = require("http"); const querystring= require('querystring'); http.createServer ...
- 在虚拟机中安装Ubuntu Server 15.04
学Linux,上红联! 红联Linux门户|Linux通用技术|Linux发行版技术|Linux企业应用|Linux实验室|红联Linux论坛 Linux系统教程 Linux入门 Linux管理 Li ...
- NodeJS错误处理最佳实践
NodeJS的错误处理让人痛苦,在很长的一段时间里,大量的错误被放任不管.但是要想建立一个健壮的Node.js程序就必须正确的处理这些错误,而且这并不难学.如果你实在没有耐心,那就直接绕过长篇大论跳到 ...
- 如何提高NodeJS程序的运行的稳定性
如何提高NodeJS程序运行的稳定性 我们常通过node app.js方式运行nodejs程序,但总有一些异常或错误导致程序运行停止退出.如何保证node程序的稳定运行? 下面是一些可以考虑的方案: ...
- Ubuntu Server16.04 安装Odoo11
odoo11采用了python3实现的. 1.sudo adduser odoo //新建一个用户odoo 2.给odoo 用户root 权限 visudo //使用visudo 编辑 /et ...
- [Java 教程 04] Java基础语法
在上一篇文章中我们已经运行了个简单的java程序,但是没有给大家讲解代码部分的内容与含义.学习,我们要做到知其然而知其所以然,所以本篇文章我们就来讲解java程序的基本语法,学完这篇文章你再回头看上篇 ...
- qnx gpio
in order to set gpio in qnx, you can use msmgpiotool # msmgpiotool gpiotool usage: gpiotool <comm ...
- [Intel Edison开发板] 04、Edison开发基于nodejs和redis的服务器搭建
一.前言 intel-iot-examples-datastore 是Intel提供用于所有Edison开发板联网存储DEMO所需要的服务器工程.该工程是基于nodejs和redis写成的一个简单的工 ...
- Angularjs学习---angularjs环境搭建,ubuntu 12.04下安装nodejs、npm和karma
1.下载angularjs 进入其官网下载:https://angularjs.org/,建议下载最新版的:https://ajax.googleapis.com/ajax/libs/angular ...
随机推荐
- 在WildFly中运行多个standalone模式的实例
WildFly作为一款优秀的EJB容器,其前身为JBoss AS.JBoss作为一款开源的应用服务器,被广泛的应用在各种项目当中.假设我们现在有这样一个项目,他是以standalone的模式运行在 ...
- python面向对象初级(七)
概述 面向过程:根据业务逻辑从上到下写垒代码 函数式:将某功能代码封装到函数中,日后便无需重复编写,仅调用函数即可 面向对象:对函数进行分类和封装,让开发“更快更好更强...” 面向过程编程最易被初学 ...
- RedHat的定制安装
1.前提是先安装好VMware,接着打开VMware软件,选择新进虚拟机.选择Custom 2.选择iso --使用镜像文件安装. 3.选择操作系统和版本. 4.给产生的配置的文件给放在你新建的文件夹 ...
- Google 地图 API V3 之事件
Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...
- 暴力枚举N级子域名
#!/usr/bin/env python# -*- encoding: utf-8 -*-# A simple and fast sub domains brute tool for pentest ...
- IIS ARR 负载均衡
阅读:http://www.cnblogs.com/jesse2013/p/dlws-loadbalancer2.html 自定义端口:http://www.th7.cn/Program/net/20 ...
- 适配iOS10以及Xcode8
现在在苹果的官网上,我们已经可以下载到Xcode8的GM版本了,加上9.14日凌晨,苹果就要正式推出iOS10系统的推送了,在此之际,iOS10的适配已经迫在眉睫啦,不知道Xcode8 beat版本, ...
- CSS大杂烩(1)
box-sizing 有4种方式 border-box 用来减去padding内边框和边框 前提是设置好固定宽高 content-box 在宽和高之外内边距和边框 其实基本上和原来一样 inherit ...
- 关于Spring中的<context:annotation-config/>配置
当我们需要使用BeanPostProcessor时,直接在Spring配置文件中定义这些Bean显得比较笨拙,例如: 使用@Autowired注解,必须事先在Spring容器中声明AutowiredA ...
- PHP 语言特性
一.PHP 超级全局变量 PHP 超级全局变量列表: $GLOBALS $_SERVER $_REQUEST $_POST $_GET $_FILES $_ENV $_COOKIE $_SESSION ...