practice

gulp

使用gulp作为构建工具

livereolad

  • nodemon
  • supervisor

以前是

  1. $ node app.js

现在是

  1. $ nodemon app.js

唯一的问题就是debug比较麻烦

pm2 和forever

  • forever 过时了
  • pm2 现在用的最多

https://github.com/Unitech/pm2

browser-sync

  • browser-sync
  1. gulp.task('less_server',['build_less'] ,function () {
  2. browserSync.init({
  3. proxy: "127.0.0.1:3005"
  4. })
  5. gulp.watch('./public/css/main.less', ['build_less']);
  6. gulp.watch('./public/*.html',function () {
  7. browserSync.reload();
  8. });
  9. });

自动挂载路由

  • mount-routes

http://github.com/moajs/mount-routes

  1. var express = require('express')
  2. var app = express()
  3. var mount = require('mount-routes');
  4. // simple
  5. // mount(app);
  6. // with path
  7. // mount(app, __dirname + '/routes2');
  8. // with path & api dump
  9. mount(app, __dirname + '/routes2', true);
  10. // start server
  11. app.listen(23018)

open

  1. var express = require('express');
  2. var app = express();
  3. var path = require('path');
  4. var open = require("open");
  5. app.get('/', function (req, res) {
  6. res.send('Hello World')
  7. })
  8. // 随机端口3000 - 10000 之间
  9. app.listen(4001)
  10. open("http://127.0.0.1:4001");