• Stars
    star
    344
  • Rank 119,047 (Top 3 %)
  • Language
    JavaScript
  • Created almost 12 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Sample application built with Backbone, RequireJS and Twitter Bootstrap on the client and Node.js (Express.js, Mongoose) on the server.

What's this?

ClientManager is a sample CRUD application build with Backbone, RequireJS (2.0) and Twitter Bootstrap on the frontend. The backend part of the application uses Express.js and Mongoose (amongst other libraries).

Quick start

  • Make sure Node.js and NPM should be installed (I prefer to do it using NVM). This project was developed on Node 0.6.x.

  • Install project dependencies with NPM by running the following command in the terminal (project root):

    npm install .

  • Configure the ports for the application (for multiple environments: dev, test, production) and also the settings for the MongoDB connection (you can either host MongoDB locally or try a free hosting provider such as MongoLab). The config data is in /config

  • Start the server:

    a) Production

    npm start

    b) Development (note that if you want to load all the files uncompressed you should visit http://<server>:<port>/dev.html):

    node app.js

App structure

The application has a structure similar to Rails:

  • the model and controller folders are within '/app'
  • the configuration stored into json files in '/config'.
  • public directory for the server: '/public'
  • logs are kept into their own '/logs' folder, having one file per environment
  • '/lib' is where application specific files reside
  • all backend test files are inside '/test', structured into: unit tests ('/unit'), functional tests ('/functional') and the fixtures
  • the Jakefile: similar to make or rake, can run tasks

Frontend:

  • the '/js' folder is where the 'magic' happens: '/main.js' is the starting point (stores RequireJS configuration), which calls '/app' (that deals with the initialization for the application), the rest of the foldes are self-explanatory
  • '/css' and '/img' stores the static stylesheets and images needed
  • '/test' has the logic for the test runner (with Mocha), and specs

Dev gotchas with Jake (in the terminal)

Empty the database:

jake db:empty

Populate database with data:

jake db:populate[20]

That will empty db and insert 20 new records).

Compress & concatenate assets (one file for JS & one file for CSS):

jake app:assets

Testing

I've chosen Mocha for all tests in this project. To run test suite in the command line use the following command in the application root (make sure things are setup properly -> the app can connect to MongoDB, can bind to the specified port):

npm test

If you're testing on Windows, run the following commands in the terminal:

npm install [email protected] -g
mocha --ui bdd --recursive --reporter spec --timeout 10000 --slow 300

The first command installs mocha globally and the second one runs the test suite.

For client side tests, open the browser

http://<server>:<port>/test

Small JS styleguide for the project

  • 2 spaces for indentation
  • Semicolons should be used
  • Line length should be 80 (that's a soft limit, 82-83 for example is ok provided these are just a few exceptions)
  • Braces go on the same line as the statement
  • Vars should always be declared at the top
  • Variables and properties should use lower camel case capitalization

Browser compatibility

I haven't had time to properly test the app, but it should work fine in modern browsers.

TODO / Improvements:

Client-side:

  • Add popups after deleting / saving client
  • More tests

Server-side:

  • Bug in IE => should send Dates using miliseconds instead of the toString() stuff
  • Split contents of utils.js into multiple files (more specific categories)
  • Implement content-negotiation (return 406 Not Acceptable where needed) [this is present by default in Express 3.x, upgrade when it is stable enough]
  • Implement authentication and check authorization when modifying resources (OAuth maybe?)
  • Implement ETags properly for the /clients and /clients/:id GET routes

Useful links that helped me while developing this app

License

(The MIT License)

Copyright (c) 2012 Alexandru Vladutu [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

airpair-nodejs-mistakes

Top 10 Mistakes Node.js Developers Make - Airpair article (sample code)
JavaScript
73
star
2

get-folder-size

Get the size of a folder by recursively iterating through all its sub(files && folders).
JavaScript
72
star
3

dynroute

Node CLI tool for dynamic DNS using Route53
JavaScript
46
star
4

Nodetuts

All the files needed for the nodetuts.com episodes & some node.js tests of my own
JavaScript
43
star
5

mastering_express_code

Source code for the book "Mastering Web Application Development with Express"
JavaScript
27
star
6

dotfiles

[DEPRECATED] see https://github.com/alessioalex/vim-setup for vim stuff
Vim Script
15
star
7

treeIt

Convert your JavaScript objects to HTML, no additional hassle and NO <pre> tags involved.
JavaScript
10
star
8

try-json-parse

Just like JSON.parse(), except that it doesn't throw an error for invalid JSON, it just returns null
JavaScript
9
star
9

angular2-browserify

Angular 2 && TypeScript via browserify
TypeScript
8
star
10

is-binary

Detects if a file is binary based on its content.
JavaScript
8
star
11

dev-error-handler

HTTP error-handling middleware that displays syntax highlighted source code.
JavaScript
8
star
12

git-grep

Easily search a git repo in a Node streamy way (by shelling out to git-grep(1)).
JavaScript
7
star
13

karlsruhejs

KarlsruheJS meetup
7
star
14

reloadify

A live-reload NPM module that works well with your raw Node / Express servers. CLI version available as well.
JavaScript
7
star
15

git-blame

Shelling out to git blame in a streaming Node fashion.
JavaScript
6
star
16

spawn-to-readstream

Make child_process.spawn behave like a read stream, emit error event with full message (and not emit 'end' event wrongfully).
JavaScript
6
star
17

generic-middleware

Like Connect/Express middleware, but you can use it for everything.
JavaScript
6
star
18

inject-html

Node module for injecting HTML code before or after the `body` tag into the response.
JavaScript
6
star
19

git-parse-commit

Parse git commit data, like the one we get when running `git rev-list ...`.
JavaScript
6
star
20

git-diff-tree

Shelling out to git-diff-tree(1) in a Node streamy fashion
JavaScript
5
star
21

app-title

Node module that will setup the process.title for your application automagically
JavaScript
5
star
22

pump-chain

A module that glues pump and bubble-stream-error to make life easier when piping streams internally and returning an outer stream.
JavaScript
5
star
23

git-commits

Get the commit history of a repo in a Node streamy way by shelling out to git-rev-list(1).
JavaScript
4
star
24

recursive-object-proxy

Like ES6 proxies but deeper. Will notify you whenever a property of an object is updated, no matter how nested it is.
JavaScript
4
star
25

git-spawned-stream

Create a readable stream from a spawned git process.
JavaScript
4
star
26

git-count-commits

Get the total number of commits for a repo and a specific revision by shelling out to git.
JavaScript
4
star
27

reddit-api-client

Barebones Reddit API client for Node.js
JavaScript
4
star
28

bubble-stream-error

Bubble errors from sub-streams to a master stream.
JavaScript
4
star
29

LogIt

Logging library for Node.js, store independent, inspired by jog and tracer.
JavaScript
4
star
30

Cls

An interface for classical object oriented programming in JavaScript.
JavaScript
3
star
31

pkg-builder

Install your app's NPM packages programatically.
JavaScript
3
star
32

nice-error

Node.js module for making errors loggable / readable / serializable etc.
JavaScript
3
star
33

custom-err

Create an error with custom properties in Node.
JavaScript
3
star
34

eslintrc

My own take on a JavaScript style guide. (DEPRECATED)
3
star
35

response-spy

Intercepts HTTP response headers && body (without any man-in-the-middle http proxy server)
JavaScript
3
star
36

express-etaggable

Express middleware that handles the Etag caching mechanism for you and only calls the dynamic function to load the content when needed.
JavaScript
3
star
37

git-tree

Stream the content of a git tree object by shelling out to git-ls-tree(1)
JavaScript
3
star
38

limit-spawn

Kills a child process created with spawn after X bytes are sent
JavaScript
2
star
39

split-transform-stream

A combination of through2 and split with a straightforward interface.
JavaScript
2
star
40

npm-dep-chain

Get all the NPM dependencies for a module / set of modules (goes down the stack, for all the subdependencies etc)
JavaScript
2
star
41

Presentations

Presentations
JavaScript
2
star
42

git-authors

List all authors that have contributed to a git project in descending order, based on the number of commits.
JavaScript
2
star
43

waterfallize

Control flow library, similar to async.waterfall but with a different API and faster.
JavaScript
2
star
44

parallelize

control flow library for parallel async functions; it invokes the callback with the aggregated results or an error
JavaScript
2
star
45

ng-changelog

Changelog generator based on the Angular git commit message conventions.
JavaScript
2
star
46

npm-republicate

Replicate an NPM module (along with its deps) from registry A to registry B (by publishing it && its deps).
JavaScript
2
star
47

git-submodules

Get submodules data (name, path, url) for a git repo.
JavaScript
1
star
48

asyncache

Transparently cache your asynchronous get functions.
JavaScript
1
star
49

git-get-file

Return a stream with the contents of file at the revision ref.
JavaScript
1
star
50

to-generator

Transform an Array | Object into a Generator object.
JavaScript
1
star
51

json-inherit

Requiring JSON files with inheritance baked in.
JavaScript
1
star
52

node-self-registry

Private NPM registry that only replicates the specified modules from NPM [work in progress].
1
star
53

git-count-files

Get the total number of files for a repo and a specific revision by shelling out to git.
JavaScript
1
star
54

git-execute

Utility module over `child_process.exec` for git commands.
JavaScript
1
star
55

tiny-algos

daily coding challenges in JS
JavaScript
1
star
56

size-on-disk

Get folder size on disk by shelling out to du (disk usage cmd).
JavaScript
1
star
57

reddit-notifier

Receive a pushover notification whenever a user posts something on reddit. [WIP]
JavaScript
1
star
58

vim-setup

My vim setup - with an installer
Vim Script
1
star
59

git-download-archive

Get a tar/zip archive stream from a git repository (at a certain commit).
JavaScript
1
star
60

debug-app

debug module with a default namespace consisting of the application name and current filename.
JavaScript
1
star
61

browser-event-debugger

For those moments when you don't know who's adding event listeners on a page.
JavaScript
1
star
62

tiny-filter-async

Async filter function, similar to async.filter
JavaScript
1
star
63

git-get-patch

Returns a readable stream with a git patch.
JavaScript
1
star
64

linguist-data

linguist's languages.yml in JSON format
JavaScript
1
star
65

eslint-config-alessioalex

eslint sharable config, personal flavour
JavaScript
1
star
66

tiny-map-async

Asynchronous version of map that is similar to async.map, but has extra goodies included.
JavaScript
1
star
67

DelayME

Serving static files with delay style. Useful for testing what an external script might do to your application if you put it in <head> ;)
JavaScript
1
star
68

tiny-each-async

Asynchronous iterator function for parallel processing.
JavaScript
1
star
69

fronteers_node_talk

JavaScript
1
star
70

visual-diff

Visual diff two websites, alpha tool edition.
JavaScript
1
star
71

standard

My own flavor of the standard linter.
JavaScript
1
star
72

git-show-ref

List the references from the local repository in a Node streamy way (by shelling out to git-show-ref(1)).
JavaScript
1
star
73

todo-projects-wishlist

Things I would like to learn and experiment with.
1
star
74

shebang

Node module for extracting normalized shebang command token
JavaScript
1
star
75

parent-package

Recursive search (folder path upwards) until the (/some) package.json data is found.
JavaScript
1
star
76

markdown-editor

Markdown editor with live preview, inspired by https://github.com/thlorenz/browserify-markdown-editor
CSS
1
star
77

npm-pkginfo

Lightweight version of npm-registry-client#get with configurable cache stores
JavaScript
1
star
78

trace-current

Node.js module that returns the stacktrace for the current position.
JavaScript
1
star
79

level-remove-notfound

Remove the check for notFoundError when using levelUp.get()
JavaScript
1
star
80

frontpage-hn

Retrieves the front page stories from Hacker News in JSON format
HTML
1
star
81

rfifa-bot

JavaScript
1
star
82

git-name-rev

Find symbolic names for given revs by shelling out to Git (namely git-name-rev(1))
JavaScript
1
star
83

locked-atomic-ws

A combination of fs-write-stream-atomic and node-proper-lockfile to ensure that no more than one (atomic) write stream can be used at a time for a certain file.
JavaScript
1
star
84

css-stream

wip
JavaScript
1
star
85

express-var-dump

Express view helper inspired by PHP's var_dump()
JavaScript
1
star