Created
November 14, 2013 21:12
-
-
Save kuryaki/7474407 to your computer and use it in GitHub Desktop.
small start API project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| test/someTest.js | |
| */ | |
| 'use strict'; | |
| require('should'); | |
| var supertest = require('supertest'); | |
| var app = require('../app'); | |
| var request = supertest(app); | |
| describe('the tests'); | |
| /* | |
| app.js | |
| */ | |
| var express = require('express') | |
| , http = require('http') | |
| , config = require('./config'); | |
| var app = express(); | |
| app.set('port', process.env.PORT || 3000); | |
| require('./router')(app); | |
| http.createServer(app).listen(app.get('port'), function() { | |
| console.log('Notification API up and running on port ' + app.get('port')); | |
| }); | |
| module.exports = app; | |
| /* | |
| config.js | |
| */ | |
| var config = { | |
| development: {}, | |
| test: {}, | |
| production: {} | |
| } | |
| module.exports = config[process.env.NODE_ENV || 'development']; | |
| /* | |
| router.js | |
| */ | |
| var controller = require('controller.js'); | |
| module.exports = function(app){ | |
| app.get('*', controller.hello); | |
| } | |
| /* | |
| controller.js | |
| */ | |
| var MyModel = require('./Model'); | |
| var controller = { | |
| hello: function(req, res, next){ | |
| MyModel.sayHi('arguments', function(error, result){ | |
| if(error){next(error);return;} | |
| res.send(200, theGroup); | |
| }); | |
| } | |
| } | |
| module.exports = controller; | |
| /* | |
| Model.js | |
| */ | |
| function Model(){ | |
| } | |
| Model.sayHi = function(arguments, callback){ | |
| //DB logic | |
| callback(null, true); // first argument error, second argument response | |
| }; | |
| module.exports = Model; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment