diff --git a/.gitignore b/.gitignore index b64a055..0ed5bcd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,44 +1,45 @@ -# Logs -logs -*.log -npm-debug.log* - -# Runtime data -pids -*.pid -*.seed - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules -jspm_packages - -# Optional npm cache directory -.npm - -# Optional REPL history -.node_repl_history - -# Upload File -uploads -/public/images/snap/ -/public/images/favicon/ -.tags -package-lock.json \ No newline at end of file +# Logs +logs +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules +jspm_packages + +# Optional npm cache directory +.npm + +# Optional REPL history +.node_repl_history + +# Upload File +uploads +/public/images/snap/ +/public/images/favicon/ +.tags +package-lock.json +config.js \ No newline at end of file diff --git a/README.md b/README.md index ab9b8bc..c378ac5 100644 --- a/README.md +++ b/README.md @@ -172,7 +172,7 @@ source /home/lcq/schema.sql; // 执行schema.sql文件创建数据库表格。 3、安装Redis 安装教程。如果不会,请戳教程[Redis 安装教程](http://baidu.luchenqun.com/?redis%20%E5%AE%89%E8%A3%85 "Redis 安装教程"),安装完成之后如果Redis没有启动,请启动Redis。 4、安装Node.js。Node.js版本至少要求8.0以上。不会的话,请按照上面步骤1、3提供的方法自行解决。 5、克隆代码`git@github.com:luchenqun/my-bookmark.git`,切换到项目根目录下面,执行`npm install`安装package。 -6、更新/database/db.js文件的dbConfig配置,将你mysql的数据信息更新上去。 +6、在根目录,根据`config.default.js`文件内容创建一个新的文件`config.js`,更新你的MySQL的账号密码信息。注意,该账号必须要有写数据库的权限! 7、如果上面的都做好了,在项目根目录下面执行`node ./bin/www`,如果是开发,可以使用`npm start`。 8、在浏览器里面输入:127.0.0.1:2000。 9、部署的话,推荐使用nginx作为HTTP和反向代理服务器,使用forever让nodejs应用后台执行。相关知识,请自行百度。 diff --git a/config.default.js b/config.default.js new file mode 100644 index 0000000..4546902 --- /dev/null +++ b/config.default.js @@ -0,0 +1,11 @@ +module.exports = { + 'dbConfig': { + host: '127.0.0.1', + user: 'test', // mysql的账号 + password: '123456', // mysql 的密码 + database: 'mybookmarks', + multipleStatements: true, + useConnectionPooling: true, + port: 3306 + } +} \ No newline at end of file diff --git a/database/db.js b/database/db.js index 8eeb72f..2c174bb 100644 --- a/database/db.js +++ b/database/db.js @@ -1,4 +1,11 @@ var mysql = require('mysql'); +var dbConfig = null; +try { + dbConfig = require('../config.js').dbConfig; +} catch (error) { + dbConfig = require('../config.default.js').dbConfig; +} + var dbConfig = { host: '127.0.0.1', user: 'test', // mysql的账号