# gac-350 node development env set up 本文详细介绍基于gac-350 门禁的node windows 开发环境的搭建,以及用以该门禁远程编译调试node工程。 gac-350 `smart-device-node` 工程代码通过[gitlab](http://gitlab.mxj360.com/)管理. * [smart-device-node gitlab](http://gitlab.mxj360.com/smart-device/smart-device-node/tree/master) > **提示**:在`MyDreamPlus` 环境可能连接[aws.ovpn]()连接[gitlab](http://gitlab.mxj360.com/)),初次下载应用包后需要手动解压根目录下咱node_modules.zip 压缩包。 gac-350 smart-device-node 通过typescript 编码实现,ts通过解释成js后运行。 - [typestript](https://www.typescriptlang.org/docs/home.html) - [TypeScript in 5 minutes](https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html) - [Running and debugging TypeScript](https://www.jetbrains.com/help/idea/running-and-debugging-typescript.html) - [Running and Debugging Node.js](https://www.jetbrains.com/help/idea/running-and-debugging-node-js.html) 集成开发环境使用itellij,习惯vs的可以选择vs201x/vscode. * [ide itellij idea](https://www.jetbrains.com/idea/download/#section=windows) gac-350 门禁通过supervisor守护node 工程运行,程序入口通过supervisor配置文件到npm start 再到 `packge.json` 包管理的start命令。 ``` supervisor->smart-device-node->npm start->packge.json->node node_modules/cross-env/dist/bin/cross-env.js DEBUG=info:app:*,error:app:* node app/App ``` ## install and compile ### itellij itellij 直接通过 [ide itellij idea](https://www.jetbrains.com/idea/download/#section=windows)官方下载,直接双击安装,成功安装后破解参考[IntelliJ IDEA 最新注册码](https://guobinhit.blog.csdn.net/article/details/89040919)。 * 修改本机host文件 ```bash 0.0.0.0 account.jetbrains.com 0.0.0.0 www.jetbrains.com ``` * 添加注册码 ```bash 56ZS5PQ1RF-eyJsaWNlbnNlSWQiOiI1NlpTNVBRMVJGIiwibGljZW5zZWVOYW1lIjoi5q2j54mI5o6I5p2DIC4iLCJhc3NpZ25lZU5hbWUiOiIiLCJhc3NpZ25lZUVtYWlsIjoiIiwibGljZW5zZVJlc3RyaWN0aW9uIjoiRm9yIGVkdWNhdGlvbmFsIHVzZSBvbmx5IiwiY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9maWxlIENBggkA0myxg7KDeeEwEwYDVR0lBAwwCgYIKwYBBQUHAwEwCwYDVR0PBAQDAgWgMA0GCSqGSIb3DQEBCwUAA4ICAQAF8uc+YJOHHwOFcPzmbjcxNDuGoOUIP+2h1R75Lecswb7ru2LWWSUMtXVKQzChLNPn/72W0k+oI056tgiwuG7M49LXp4zQVlQnFmWU1wwGvVhq5R63Rpjx1zjGUhcXgayu7+9zMUW596Lbomsg8qVve6euqsrFicYkIIuUu4zYPndJwfe0YkS5nY72SHnNdbPhEnN8wcB2Kz+OIG0lih3yz5EqFhld03bGp222ZQCIghCTVL6QBNadGsiN/lWLl4JdR3lJkZzlpFdiHijoVRdWeSWqM4y0t23c92HXKrgppoSV18XMxrWVdoSM3nuMHwxGhFyde05OdDtLpCv+jlWf5REAHHA201pAU6bJSZINyHDUTB+Beo28rRXSwSh3OUIvYwKNVeoBY+KwOJ7WnuTCUq1meE6GkKc4D/cXmgpOyW/1SmBz3XjVIi/zprZ0zf3qH5mkphtg6ksjKgKjmx1cXfZAAX6wcDBNaCL+Ortep1Dh8xDUbqbBVNBL4jbiL3i3xsfNiyJgaZ5sX7i8tmStEpLbPwvHcByuf59qJhV/bZOl8KqJBETCDJcY6O2aqhTUy+9x93ThKs1GKrRPePrWPluud7ttlgtRveit/pcBrnQcXOl1rHq7ByB8CFAxNotRUYL9IF5n3wJOgkPojMy6jetQA5Ogc8Sm7RG6vg1yow== ``` ### node node 解释器和sdk通过[nodejs.org](https://nodejs.org/zh-cn/),成功下载后双击默认安装。 ### run 成功安装itellij后通过New->Project->node->Node.js and NPM 导入代码到工程。 > **提示**:初次下载工程需要手动解压根目录下在的node_modules.zip压缩包。 如果要在windows上面编译工程,需要添加 Run-> Edit Configurationss->+ npm * package.json 为工程根目录下的`package.json` 文件; * command 为`start` * Node interprter 为如上node安装路径。 * 详细配置如下: ![itellij debug node](http://docs.leconiot.com/lib/exe/fetch.php?media=jaysnote:images:intellij_node_debug.png) 同时可配置远程机器运行直接配置到gac-350门禁上运行调试。 * 初次使用该功能需要手动添加node.js 远程解释器插件。 File->Settings/Preferences (Ctrl+Alt+S)-> Plugins->Maketplace->Node.js Remote Interpreter; > **提示**:详细参考[Configure Node.js Remote Interpreter Dialog](https://www.jetbrains.com/help/idea/configure-node-js-remote-interpreter.html) * 成功安装node.js 远程插件过后通过Run-> Edit Configurationss->+ Node.js * 详细配置如下图: ![远程调试](http://docs.leconiot.com/lib/exe/fetch.php?media=jaysnote:images:note_js_remote_interpreter.png) > **提示**: 需要提前远程设备root账号和密码,同时允许ssh root账号登录。 ## troubleshooting ### 编译失败 ```bash Error:(2, 21) TS2307: Cannot find module 'fs'. Error:(6, 16) TS2503: Cannot find namespace 'NodeJS'. ``` ### 本地运行提示 Cannot find cross-env.js ```bash internal/modules/cjs/loader.js:584 throw err; ^ Error: Cannot find module 'D:\MyProject\smart-device-node\node_modules\cross-env\dist\bin\cross-env.js' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15) at Function.Module._load (internal/modules/cjs/loader.js:508:25) at Function.Module.runMain (internal/modules/cjs/loader.js:754:12) at startup (internal/bootstrap/node.js:283:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3) ``` 如上文,已经反复提示,初次安装需要手动解压安装根目录下的node_modules.zip 压缩包。 ### 远程调试提示Illegal instruction ```bash /usr/bin/node --inspect=0.0.0.0:57309 --debug-brk app/App node_modules/cross-env/dist/bin/cross-env.js bash: line 1: 11260 Illegal instruction env "FORCE_COLOR"="true" "ELECTRON_NO_ATTACH_CONSOLE"="true" "npm_config_color"="always" "DEBUG_COLORS"="true" "MOCHA_COLORS"="1" "DEBUG"="info:app:*,error:app:* " "JETBRAINS_REMOTE_RUN"="1" "COLORTERM"="true" '/usr/bin/node' '--inspect=0.0.0.0:57309' '--debug-brk' 'app/App' 'node_modules/cross-env/dist/bin/cross-env.js' ``` 暂时地,门禁版本过于7,不支持debug功能。 '--inspect=0.0.0.0:57546' 参数无效 https://nodejs.org/zh-cn/docs/guides/debugging-getting-started/ ```bash 在版本 7 以及更早的版本使用 --debug 或 --debug-brk 开关启动调试时,Node.js 侦听由中断定义的调试命令,TCP 端口上的 V8 调试协议,默认为 5858。任何遵守此协议的调试客户端都可以连接并调试运行这个进程,下面有一些热门的说明。 ``` http://mirrors.sohu.com/debian/pool/main/n/nodejs/ 低版本node不支持itellij 调试,需要安装高版本的node->debian Jessie 版本太低不支持高版本node所以需要切换到sid、experimental 源更新libc和gcc->装了高版本node过后发现npm 不在了,通过apt-get install 重新安装了npm。->之后发现electron不能正常启动。