`
sillycat
  • 浏览: 2551188 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

NODEJS(16)Platform - gulp and REST structure

 
阅读更多

NODEJS(16)Platform - gulp and REST structure

1. Prepare the mongo DB
Get the file from here https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-2.6.5.tgz
Place it in the right place and add to path
>sudo mkdir -p /data/db
>sudo chown carl /data/db
>sudo mkdir /var/log/mongodb
>sudo chown carl /var/log/mongodb
>mkdir /data/db/mongodb

Start the mongo server
>mongod -f conf/mongodb.conf

Connect to the server
>mongo --host 127.0.0.1 --port 27017

Get the GUI http://mongohub.todayclose.com/

2. Prepare memcached
http://memcached.org/

Command to start memcached server
>memcached -d -m 50 -p 11211 -u carl -l 0.0.0.0

There is a project in easynodejs/buglist for references.
http://sillycat.iteye.com/blog/2072384

3. gulp structure for Server side Project
The example is in here.
https://github.com/luohuazju/winner-seller-console/tree/master/order-rest-api

package.json for dependencies
{
  "devDependencies": {
    "gulp": "3.8.10",
    "gulp-jshint" : "1.9.0",
    "gulp-mocha" : "1.1.1",
    "gulp-nodemon" : "1.0.4",
    "gulp-util" : "3.0.1",
    "express" : "4.10.2"
  },
  "engines": {
    "node": ">=0.11.0"
  },
  "license": "MIT",
  "name": "order-rest-api",
  "private": true,
  "version": "0.0.1"
}

gulpfile.js for management project
/*jslint node: true */
'use strict';

//gulp &  plugins
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');
var nodemon = require('gulp-nodemon');
var gutil = require('gulp-util');
 
gulp.task('default', ['develope']);
gulp.task('develope', ['lint', 'test', 'serve', 'watch']);

 
var paths = {
  main    : 'app.js',
  tests   : 'test/**/*.js',
  sources : [ '**/*.js', '!node_modules/**']
};
 
// lint all of our js source files
gulp.task('lint', function (){
  return gulp.src(paths.sources)
    .pipe(jshint())
    .pipe(jshint.reporter('default'));
});
 
// run mocha tests
gulp.task('test', function (){
  return gulp.src(paths.tests, {read: false})
  .pipe(mocha({reporter: 'list'}))
  .on('error', gutil.log);
});
 
//run app using nodemon
gulp.task('serve', [], function(){
  return nodemon({
    script: 'server.js',
    watch   : paths.sources
  });
});
 
// will watch client files and rebuild on change
gulp.task('watch', function(){
  gulp.watch(paths.sources, ['lint']);
});

Easy Hello world app.js
/*jslint node: true */
'use strict';

var express = require('express');
var app = express();

app.get('/hello', function(req, res){
     res.send('Hello Sillycat');
});

app.listen(3000);
console.log('Listening on port 3000');

Command for gulp
>gulp lint
Check all the JS file

Run test
>gulp test

Start the app server
>gulp serve

Visit the demo
http://localhost:3000/hello

References:
http://underscorejs.org/#each
http://sillycat.iteye.com/blog/2072384

mongodb
http://sillycat.iteye.com/blog/1965857
http://sillycat.iteye.com/blog/2065123

memory cache
http://sillycat.iteye.com/blog/2066119

gulp
https://github.com/arvsr1988/gulp-expressjs-setup
http://stackoverflow.com/questions/23665993/gulp-js-livereload-with-express-server
https://gist.github.com/hansent/9417349
http://help.nitrous.io/setting-up-gulp-with-livereload-and-sass/
http://fairwaytech.com/2014/01/understanding-grunt-part-2-automated-testing-with-mocha/

mocha
http://unitjs.com/guide/mocha.html

rabbitmq
https://github.com/postwait/node-amqp


 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics