Skip to content

builden/node.cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.cpp

  • 用C++实现了Node.js的常用API接口
  • 底层使用libuv, 支持事件驱动、非阻塞IO
  • 实现了几个Node.js项目中被大量依赖的第三库
  • 使用方式基本上和Node.js保持一致,开发过程中可直接参考Node.js的API文档
  • 大量使用了C++11中的lambda,动态参数模版等特性,目前只在VS2015中编译通过

为何不直接在Windows客户端直接使用Node.js

  • 最新的Node.js已经不支持xp系统
  • Node.js目前在前端容易遭到破解
  • Node.js本身的尺寸较大,安装包在11M左右

使用示例

// fs
fs.readFile(filePath, [](const Buffer& buf) {
  ...
});

内置库

  • buffer
  • core-math // js内置的math库
  • child_process
  • crypto
  • dns
  • fs
  • http
  • net
  • os
  • stream
  • path
  • process
  • querystring
  • thread
  • timers
  • url
  • zlib

第三方库

  • lodash
  • underscore.string
  • moment
  • iconv
  • file-url
  • commander
  • later
  • semver
  • winreg

自用库

  • keyboard-code-trans
    • 字符串转键盘虚拟键值

    灵感来自于Electron

  • wm-code-trans
    • WindowsMessage转字符串
  • pe-cert
    • 用于检测程序的数字签名
  • shm
    • 共享内存
  • dll-util
    • 包装了对dll的一些常用操作,如获取dll的绝对路径
  • detours-hooker
    • 包装了detours,方便hooker api,启动进程前注入dll
  • ini
    • 包装了ini文件的解析

工具类

  • singleton
    • 单例的包装类
  • std-redex-ex
    • 扩展了std::regex_replace

    支持formart回调

初始化编译

  1. 需提前编译Detours.lib放入

    nmake

  2. 需安装CMake,并为glog3生成工程

    cmake -G "Visual Studio 14"

  3. 需安装gyp

    gyp --depth=. xxx.gyp

  4. 在deps目录,下载各个模块
git clone -b 1.2 https://github.com/KjellKod/g3log.git
git clone -b v2.7.0 https://github.com/nodejs/http-parser.git
git clone -b v1.2.8 https://github.com/madler/zlib.git
git clone -b release-1.7.0 https://github.com/google/googletest.git gtest
  1. 生成VS工程
  • g3log -> cmake
  • http-parser -> gyp
  • zlib -> cmake
  • openssl -> gyp
  • libuv -> vcbuild.bat
  • gtest -> cmake

工程设置

  • Output Directory: $(SolutionDir)bin$(Configuration)\
  • Intermediate Directory: $(SolutionDir)bin\obj$(Configuration)$(ProjectName)\
  • C/C++ => General => Additional Include Directory

    ../deps/uv

  • VC++ Directories => Library Directories

    $(SolutionDir)bin/$(Configuration)/lib

依赖

参考

About

用C++11实现node.js的API接口

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published