Skip to content
This repository was archived by the owner on Aug 30, 2021. It is now read-only.

Commit 17e089e

Browse files
committed
Moving to MEAN.JS
1 parent f52d6c3 commit 17e089e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+874
-1955
lines changed

.bowerrc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"directory": "public/lib",
3-
"storage": {
4-
"packages": ".bower-cache",
5-
"registry": ".bower-registry"
6-
},
7-
"tmp": ".bower-tmp"
2+
"directory": "public/lib",
3+
"storage": {
4+
"packages": ".bower-cache",
5+
"registry": ".bower-registry"
6+
},
7+
"tmp": ".bower-tmp"
88
}

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
.DS_Store
22
.nodemonignore
33
.sass-cache/
4-
.bower-*/
5-
.idea/
4+
npm-debug.log
65
node_modules/
76
public/lib
8-
test/coverage/
7+
app/tests/coverage/
8+
.bower-*/
9+
.idea/

.jshintrc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
"quotmark": "single", // Define quotes to string values.
1414
"regexp": true, // Prohibit `.` and `[^...]` in regular expressions.
1515
"undef": true, // Require all non-global variables be declared before they are used.
16-
"unused": true, // Warn unused variables.
16+
"unused": false, // Warn unused variables.
1717
"strict": true, // Require `use strict` pragma in every file.
1818
"trailing": true, // Prohibit trailing whitespaces.
1919
"smarttabs": false, // Suppresses warnings about mixed tabs and spaces
2020
"globals": { // Globals variables.
21-
"angular": true
21+
"angular": true,
22+
"ApplicationConfiguration": true
2223
},
2324
"predef": [ // Extra globals.
2425
"define",

.slugignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/test
1+
/app/tests

README.md

Lines changed: 43 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,138 +1,72 @@
1-
# MEAN Stack
1+
[![MEAN.JS Logo](http://meanjs.org/img/logo-small.png)](http://meanjs.org/)
22

3-
MEAN is a boilerplate that provides a nice starting point for [MongoDB](http://www.mongodb.org/), [Node.js](http://www.nodejs.org/), [Express](http://expressjs.com/), and [AngularJS](http://angularjs.org/) based applications. It is designed to give you quick and organized way to start developing of MEAN based web apps with useful modules like mongoose and passport pre-bundled and configured. We mainly try to take care of the connection points between existing popular frameworks and solve common integration problems.
3+
MEAN.JS is a full-stack JavaScript open-source solution, which provides a solid starting point for [MongoDB](http://www.mongodb.org/), [Node.js](http://www.nodejs.org/), [Express](http://expressjs.com/), and [AngularJS](http://angularjs.org/) based applications. The idea is to solve the common issues with connecting those frameworks, build a robust framework to support daily development needs, and help developers use better practices while working with popular JavaScript components.
4+
5+
## Before You Begin
6+
Before you begin we recommend you read about the basic building blocks that assemble a MEAN.JS application:
7+
* MongoDB - Go through [MongoDB Official Website](http://mongodb.org/) and proceed to their [Official Manual](http://docs.mongodb.org/manual/), which should help you understand NoSQL and MongoDB better.
8+
* Express - The best way to understand express is through its [Official Website](http://expressjs.com/), particularly [The Express Guide](http://expressjs.com/guide.html); you can also go through this [StackOverflow Thread](http://stackoverflow.com/questions/8144214/learning-express-for-node-js) for more resources.
9+
* AngularJS - Angular's [Official Website](http://angularjs.org/) is a great starting point. You can also use [Thinkster Popular Guide](http://www.thinkster.io/), and the [Egghead Videos](https://egghead.io/).
10+
* Node.js - Start by going through [Node.js Official Website](http://nodejs.org/) and this [StackOverflow Thread](http://stackoverflow.com/questions/2353818/how-do-i-get-started-with-node-js), which should get you going with the Node.js platform in no time.
411

5-
## Prerequisites
6-
* Node.js - Download and Install [Node.js](http://www.nodejs.org/download/). You can also follow [this gist](https://gist.github.com/isaacs/579814) for a quick and easy way to install Node.js and npm
7-
* MongoDB - Download and Install [MongoDB](http://www.mongodb.org/downloads) - Make sure it's running on the default port (27017).
812

9-
### Tools Prerequisites
10-
* NPM - Node.js package manager, should be installed when you install node.js.
11-
* Bower - Web package manager, installing [Bower](http://bower.io/) is simple when you have npm:
13+
## Prerequisites
14+
Make sure you have installed all these prerequisites on your development machine.
15+
* Node.js - [Download & Install Node.js](http://www.nodejs.org/download/) and the npm package manager, if you encounter any problems, you can also use this [Github Gist](https://gist.github.com/isaacs/579814) to install Node.js.
16+
* MongoDB - [Download & Install MongoDB](http://www.mongodb.org/downloads), and make sure it's running on the default port (27017).
17+
* Bower - You're going to use the [Bower Package Manager](http://bower.io/) to manage your front-end packages, in order to install it make sure you've installed Node.js and npm, then install bower globally using npm:
1218

1319
```
1420
$ npm install -g bower
1521
```
1622

17-
### Optional
18-
* Grunt - Download and Install [Grunt](http://gruntjs.com).
23+
* Grunt - You're going to use the [Grunt Task Runner](http://gruntjs.com/) to automate your development process, in order to install it make sure you've installed Node.js and npm, then install grunt globally using npm:
1924

20-
## Additional Packages
21-
* Express - Defined as npm module in the [package.json](package.json) file.
22-
* Mongoose - Defined as npm module in the [package.json](package.json) file.
23-
* Passport - Defined as npm module in the [package.json](package.json) file.
24-
* AngularJS - Defined as bower module in the [bower.json](bower.json) file.
25-
* Twitter Bootstrap - Defined as bower module in the [bower.json](bower.json) file.
26-
* UI Bootstrap - Defined as bower module in the [bower.json](bower.json) file.
25+
```
26+
$ sudo npm install -g grunt-cli
27+
```
2728

2829
## Quick Install
29-
The quickest way to get started with MEAN is to clone the project and utilize it like this:
30-
31-
Install dependencies:
32-
33-
$ npm install
34-
35-
We recommend using [Grunt](https://github.com/gruntjs/grunt-cli) to start the server:
30+
Once you've installed all the prerequisites, you're just a few steps away from starting to develop you MEAN application.
3631

37-
$ grunt
38-
39-
When not using grunt you can use:
32+
The first thing you should do is install the Node.js dependencies. The boilerplate comes pre-bundled with a package.json file that contains the list of modules you need to start your application, to learn more about the modules installed visit the NPM & Package.json section.
4033

41-
$ node server
42-
43-
Then open a browser and go to:
34+
To install Node.js dependencies you're going to use npm again, in the application folder run this in the command-line:
4435

45-
http://localhost:3000
46-
47-
48-
## Troubleshooting
49-
During install some of you may encounter some issues, most of this issues can be solved by one of the following tips.
50-
If you went through all this and still can't solve the issue, feel free to contact me(Amos), via the repository issue tracker or the links provided below.
51-
52-
#### Update NPM, Bower or Grunt
53-
Sometimes you may find there is a weird error during install like npm's *Error: ENOENT*, usually updating those tools to the latest version solves the issue.
54-
55-
Updating NPM:
5636
```
57-
$ npm update -g npm
37+
$ npm install
5838
```
5939

60-
Updating Grunt:
61-
```
62-
$ npm update -g grunt-cli
63-
```
40+
This command does a few things:
41+
* First it will install the dependencies needed for the application to run.
42+
* If you're running in a development environment, it will then also install development dependencies needed for testing and running your application.
43+
* Finally, when the install process is over, npm will initiate a bower installcommand to install all the front-end modules needed for the application
6444

65-
Updating Bower:
66-
```
67-
$ npm update -g bower
68-
```
69-
70-
#### Cleaning NPM and Bower cache
71-
NPM and Bower has a caching system for holding packages that you already installed.
72-
We found that often cleaning the cache solves some troubles this system creates.
45+
## Running Your Application
46+
After the install process is over, you'll be able to run your application using Grunt, just run grunt default task:
7347

74-
NPM Clean Cache:
7548
```
76-
$ npm cache clean
77-
```
78-
79-
Bower Clean Cache:
49+
$ grunt
8050
```
81-
$ bower cache clean
82-
```
83-
84-
85-
## Configuration
86-
All configuration is specified in the [config](config/) folder, particularly the [config.js](config/config.js) file and the [env](config/env/) files. Here you will need to specify your application name, database name, as well as hook up any social app keys if you want integration with Twitter, Facebook, GitHub or Google.
87-
88-
### Environmental Settings
8951

90-
There are three environments provided by default, __development__, __test__, and __production__. Each of these environments has the following configuration options:
91-
* __db__ - This is the name of the MongoDB database to use, and is set by default to __mean-dev__ for the development environment.
92-
* __app.name__ - This is the name of your app or website, and can be different for each environment. You can tell which environment you are running by looking at the TITLE attribute that your app generates.
93-
* __Social OAuth Keys__ - Facebook, GitHub, Google, Twitter. You can specify your own social application keys here for each platform:
94-
* __clientID__
95-
* __clientSecret__
96-
* __callbackURL__
52+
Your application should run on the 3000 port so in your browser just go to [http://localhost:3000](http://localhost:3000)
53+
54+
That's it! your application should be running by now, to proceed with your development check the other sections in this documentation.
55+
If you encounter any problem try the Troubleshooting section.
9756

98-
To run with a different environment, just specify NODE_ENV as you call grunt:
57+
## Getting Started With MEAN.JS
58+
You have your application running but there are a lot of stuff to understand, we recommend you'll go over the [Offical Documentation](http://meanjs.org/docs.html).
59+
In the docs we'll try to explain both general concepts of MEAN components and give you some guidelines to help you improve your development procees. We tried covering as many aspects as possible, and will keep update it by your request, you can also help us develop the documentation better by checking out the *gh-pages* branch of this repository.
9960

100-
$ NODE_ENV=test grunt
101-
102-
If you are using node instead of grunt, it is very similar:
103-
104-
$ NODE_ENV=test node server
105-
106-
> NOTE: Running Node.js applications in the __production__ environment enables caching, which is disabled by default in all other environments.
107-
108-
## Getting Started
109-
We pre-included an article example, check it out:
110-
* [The Model](https://github.com/linnovate/mean/blob/master/app/models/article.js) - Where we define our object schema.
111-
* [The Controller](https://github.com/linnovate/mean/blob/master/app/controllers/articles.js) - Where we take care of our backend logic.
112-
* [NodeJS Routes](https://github.com/linnovate/mean/blob/master/config/routes.js) - Where we define our REST service routes.
113-
* [AngularJs Routes](https://github.com/linnovate/mean/blob/master/public/js/config.js) - Where we define our CRUD routes.
114-
* [The AngularJs Service](https://github.com/linnovate/mean/blob/master/public/js/services/articles.js) - Where we connect to our REST service.
115-
* [The AngularJs Controller](https://github.com/linnovate/mean/blob/master/public/js/controllers/articles.js) - Where we take care of our frontend logic.
116-
* [The AngularJs Views Folder](https://github.com/linnovate/mean/blob/master/public/views/articles) - Where we keep our CRUD views.
117-
118-
## Heroku Quick Deployment
119-
Before you start make sure you have <a href="https://toolbelt.heroku.com/">heroku toolbelt</a> installed and an accessible mongo db instance - you can try <a href="http://www.mongohq.com/">mongohq</a> which have an easy setup )
120-
121-
```bash
122-
git init
123-
git add .
124-
git commit -m "initial version"
125-
heroku apps:create
126-
git push heroku master
127-
```
61+
## Community
62+
* Use to [Offical Website](http://meanjs.org) to learn about changes and the roadmap.
63+
* Join #meanjs on freenode.
64+
* Discuss it in the new [Google Group](https://groups.google.com/d/forum/meanjs)
65+
* Ping us on [Twitter](http://twitter.com/meanjsorg) and [Facebook](http://facebook.com/meanjs)
12866

129-
## More Information
130-
* Contact Amos Haviv on any issue via [E-Mail](mailto:mail@amoshaviv.com), [Facebook](http://www.facebook.com/amoshaviv), or [Twitter](http://www.twitter.com/amoshaviv).
131-
* Visit us at [Linnovate.net](http://www.linnovate.net/).
132-
* Visit our [Ninja's Zone](http://www.meanleanstartupmachine.com/) for extended support.
67+
## Live Example
68+
Browse the live MEAN.JS example on [http://meanjs.herokuapp.com](http://meanjs.herokuapp.com).
13369

134-
## Credits
135-
Inspired by the great work of [Madhusudhan Srinivasa](https://github.com/madhums/)
13670

13771
## License
13872
(The MIT License)

app/controllers/articles.js

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,6 @@ var mongoose = require('mongoose'),
77
Article = mongoose.model('Article'),
88
_ = require('lodash');
99

10-
11-
/**
12-
* Find article by id
13-
*/
14-
exports.article = function(req, res, next, id) {
15-
Article.load(id, function(err, article) {
16-
if (err) return next(err);
17-
if (!article) return next(new Error('Failed to load article ' + id));
18-
req.article = article;
19-
next();
20-
});
21-
};
22-
2310
/**
2411
* Create a article
2512
*/
@@ -39,6 +26,13 @@ exports.create = function(req, res) {
3926
});
4027
};
4128

29+
/**
30+
* Show the current article
31+
*/
32+
exports.read = function(req, res) {
33+
res.jsonp(req.article);
34+
};
35+
4236
/**
4337
* Update a article
4438
*/
@@ -49,9 +43,8 @@ exports.update = function(req, res) {
4943

5044
article.save(function(err) {
5145
if (err) {
52-
return res.send('users/signup', {
53-
errors: err.errors,
54-
article: article
46+
res.render('error', {
47+
status: 500
5548
});
5649
} else {
5750
res.jsonp(article);
@@ -62,33 +55,25 @@ exports.update = function(req, res) {
6255
/**
6356
* Delete an article
6457
*/
65-
exports.destroy = function(req, res) {
58+
exports.delete = function(req, res) {
6659
var article = req.article;
6760

6861
article.remove(function(err) {
6962
if (err) {
70-
return res.send('users/signup', {
71-
errors: err.errors,
72-
article: article
63+
res.render('error', {
64+
status: 500
7365
});
7466
} else {
7567
res.jsonp(article);
7668
}
7769
});
7870
};
7971

80-
/**
81-
* Show an article
82-
*/
83-
exports.show = function(req, res) {
84-
res.jsonp(req.article);
85-
};
86-
8772
/**
8873
* List of Articles
8974
*/
90-
exports.all = function(req, res) {
91-
Article.find().sort('-created').populate('user', 'name username').exec(function(err, articles) {
75+
exports.list = function(req, res) {
76+
Article.find().sort('-created').populate('user', 'displayName').exec(function(err, articles) {
9277
if (err) {
9378
res.render('error', {
9479
status: 500
@@ -97,4 +82,26 @@ exports.all = function(req, res) {
9782
res.jsonp(articles);
9883
}
9984
});
85+
};
86+
87+
/**
88+
* Article middleware
89+
*/
90+
exports.articleByID = function(req, res, next, id) {
91+
Article.load(id, function(err, article) {
92+
if (err) return next(err);
93+
if (!article) return next(new Error('Failed to load article ' + id));
94+
req.article = article;
95+
next();
96+
});
97+
};
98+
99+
/**
100+
* Article authorization middleware
101+
*/
102+
exports.hasAuthorization = function(req, res, next) {
103+
if (req.article.user.id !== req.user.id) {
104+
return res.send(403, 'User is not authorized');
105+
}
106+
next();
100107
};

app/controllers/index.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)