最近在Github上下载了一个基于NodeJs后台的微信小程序的软件,想把后台给跑起来,这里记录一下过程。我是在ubuntu上安装的,windows总是有问题。
- 后台目录文件如下:
在下载好后,需要安装最新版本的NodeJs,一开始我用apt-get安装了一个4.24的版本,后面编译出现了问题如下:12SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode这是因为Ubuntu下如果使用apt-get的话安装的是以前的版本不是最新版,所以需要到该网址下载源码包编译安装,虽然我使用这种方法编译安装没有成功,但还是记录一下步骤。编译安装的步骤如下:
解压123tar -zxf node-v6.10.1.tar.gzcd node-v6.10.1默认安装
1234./configuremakesudo make install但是我在编译安装的时候,最后使用
node -v
指令找不到node,改了环境变量也不行,非常难过的我最后直接在该链接下载了linux的编译好的node文件,参考该网页,使用以下指令解压:123xz -d node-v6.10.1-linux-x64.tar.xztar xvf node-v6.10.1-linux-x64.tar解压后的文件夹中的内容都是编译好的,然后使用以下指令复制生成的文件夹到你想要放到的地点,我复制到
usr/local/node
目录下:12cp -r node-v6.10.1-linux-x64 usr/local/node复制好后修改一下环境变量,依照该网页,即使用以下指令:
12gedit /etc/profile/然后在文件最后面添加这几句,其实这个方法相当于直接用编译好的源码,然后把他们添加到ubuntu的环境变量中:
1234export NODE_HOME=/usr/local/nodeexport PATH=$PATH:$NODE_HOME/binexport NODE_PATH=$NODE_HOME/lib/node_modules然后重启,就会发现node安装好了,并且是最新版的。
-
安装好后使用以下指令自动生成需要的module文件,先使用以下指令,会自动安装json文件中的依赖库:
12nmp install然后报错如下:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657npm WARN checkPermissions Missing write access to /home/dada/weixin/wePa-master/server/node_moduleswePa_server@0.0.1 /home/dada/weixin/wePa-master/server└─┬ bcrypt@1.0.2├── bindings@1.2.1├── nan@2.5.0└─┬ node-pre-gyp@0.6.32├─┬ nopt@3.0.6│ └── abbrev@1.1.0├─┬ npmlog@4.0.2│ ├─┬ are-we-there-yet@1.1.2│ │ └── delegates@1.0.0│ ├── console-control-strings@1.1.0│ ├─┬ gauge@2.7.3│ │ ├── aproba@1.1.1│ │ ├── has-unicode@2.0.1│ │ ├── signal-exit@3.0.2│ │ └── wide-align@1.1.0│ └── set-blocking@2.0.0├─┬ rc@1.1.7│ ├── deep-extend@0.4.1│ ├── ini@1.3.4│ ├── minimist@1.2.0│ └── strip-json-comments@2.0.1├─┬ tar@2.2.1│ ├── block-stream@0.0.9│ └── fstream@1.0.11└─┬ tar-pack@3.3.0├── debug@2.2.0├── fstream-ignore@1.0.5├── once@1.3.3├── readable-stream@2.1.5└── uid-number@0.0.6npm WARN wePa_server@0.0.1 No repository field.npm ERR! Linux 4.4.0-66-genericnpm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"npm ERR! node v6.10.1npm ERR! npm v3.10.10npm ERR! path /home/dada/weixin/wePa-master/server/node_modulesnpm ERR! code EACCESnpm ERR! errno -13npm ERR! syscall accessnpm ERR! Error: EACCES: permission denied, access '/home/dada/weixin/wePa-master/server/node_modules'npm ERR! at Error (native)npm ERR! { Error: EACCES: permission denied, access '/home/dada/weixin/wePa-master/server/node_modules'npm ERR! at Error (native)npm ERR! errno: -13,npm ERR! code: 'EACCES',npm ERR! syscall: 'access',npm ERR! path: '/home/dada/weixin/wePa-master/server/node_modules' }npm ERR!npm ERR! Please try running this command again as root/Administrator.npm ERR! Please include the following file with any support request:npm ERR! /home/dada/weixin/wePa-master/server/npm-debug.log这时候发现是因为没有sudo,所以使用以下指令继续跑:
12sudo npm install然后报错如下:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748> bcrypt@1.0.2 install /home/dada/weixin/wePa-master/server/node_modules/bcrypt> node-pre-gyp install --fallback-to-buildnode-pre-gyp ERR! Tried to download(404): https://github.com/kelektiv/node.bcrypt.js/releases/download/v1.0.2/bcrypt_lib-v1.0.2-node-v48-linux-x64.tar.gznode-pre-gyp ERR! Pre-built binaries not found for bcrypt@1.0.2 and node@6.10.1 (node-v48 ABI) (falling back to source compile with node-gyp)make: Entering directory '/home/dada/weixin/wePa-master/server/node_modules/bcrypt/build'CXX(target) Release/obj.target/bcrypt_lib/src/blowfish.oCXX(target) Release/obj.target/bcrypt_lib/src/bcrypt.oCXX(target) Release/obj.target/bcrypt_lib/src/bcrypt_node.oSOLINK_MODULE(target) Release/obj.target/bcrypt_lib.nodeCOPY Release/bcrypt_lib.nodeCOPY /home/dada/weixin/wePa-master/server/node_modules/bcrypt/lib/binding/bcrypt_lib.nodeTOUCH Release/obj.target/action_after_build.stampmake: Leaving directory '/home/dada/weixin/wePa-master/server/node_modules/bcrypt/build'wePa_server@0.0.1 /home/dada/weixin/wePa-master/server└─┬ bcrypt@1.0.2├── bindings@1.2.1├── nan@2.5.0└─┬ node-pre-gyp@0.6.32├─┬ nopt@3.0.6│ └── abbrev@1.1.0├─┬ npmlog@4.0.2│ ├─┬ are-we-there-yet@1.1.2│ │ └── delegates@1.0.0│ ├── console-control-strings@1.1.0│ ├─┬ gauge@2.7.3│ │ ├── aproba@1.1.1│ │ ├── has-unicode@2.0.1│ │ ├── signal-exit@3.0.2│ │ └── wide-align@1.1.0│ └── set-blocking@2.0.0├─┬ rc@1.1.7│ ├── deep-extend@0.4.1│ ├── ini@1.3.4│ ├── minimist@1.2.0│ └── strip-json-comments@2.0.1├─┬ tar@2.2.1│ ├── block-stream@0.0.9│ └── fstream@1.0.11└─┬ tar-pack@3.3.0├── debug@2.2.0├── fstream-ignore@1.0.5├── once@1.3.3├── readable-stream@2.1.5└── uid-number@0.0.6npm WARN wePa_server@0.0.1 No repository field.这时候发现是下载不了一个文件,但是不试用sudo的时候并没有问题,所以使用以下指令继续跑:
12npm install然后报错如下:
123456789101112131415161718192021222324npm WARN wePa_server@0.0.1 No repository field.npm ERR! Linux 4.4.0-66-genericnpm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"npm ERR! node v6.10.1npm ERR! npm v3.10.10npm ERR! path /home/dada/weixin/wePa-master/server/node_modules/.stagingnpm ERR! code EACCESnpm ERR! errno -13npm ERR! syscall mkdirnpm ERR! Error: EACCES: permission denied, mkdir '/home/dada/weixin/wePa-master/server/node_modules/.staging'npm ERR! at Error (native)npm ERR! { Error: EACCES: permission denied, mkdir '/home/dada/weixin/wePa-master/server/node_modules/.staging'npm ERR! at Error (native)npm ERR! errno: -13,npm ERR! code: 'EACCES',npm ERR! syscall: 'mkdir',npm ERR! path: '/home/dada/weixin/wePa-master/server/node_modules/.staging' }npm ERR!npm ERR! Please try running this command again as root/Administrator.npm ERR! Please include the following file with any support request:npm ERR! /home/dada/weixin/wePa-master/server/npm-debug.log这时候只剩下一个权限问题,所以使用以下指令继续跑:
12sudo npm install终于成功运行。
-
然后使用以下指令运行后台
12node app.js结果如下:
12345678910111213141516Mongoose disconnectedRedis connection error: Error: Redis connection to localhost:6379 failed - connect ECONNREFUSED 127.0.0.1:6379Redis endedMongoose connection error: MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017](node:26689) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]Redis connection error: Error: Redis connection to localhost:6379 failed - connect ECONNREFUSED 127.0.0.1:6379Redis connection error: Error: Redis connection to localhost:6379 failed - connect ECONNREFUSED 127.0.0.1:6379Redis connection error: Error: Redis connection to localhost:6379 failed - connect ECONNREFUSED 127.0.0.1:6379Redis connection error: Error: Redis connection to localhost:6379 failed - connect ECONNREFUSED 127.0.0.1:6379Redis connection error: Error: Redis connection to localhost:6379 failed - connect ECONNREFUSED 127.0.0.1:6379Redis connection error: Error: Redis connection to localhost:6379 failed - connect ECONNREFUSED 127.0.0.1:6379Redis connection error: Error: Redis connection to localhost:6379 failed - connect ECONNREFUSED 127.0.0.1:6379Redis connection error: Error: Redis connection to localhost:6379 failed - connect ECONNREFUSED 127.0.0.1:6379Redis connection error: Error: Redis connection to localhost:6379 failed - connect ECONNREFUSED 127.0.0.1:6379^CMongoose disconnected through app termination这时候服务器运行已经没有问题,但是连接不上数据库,到这一步说明你的服务器环境已经搭建成功了。