NodeJS + ExpressJS + MongoDB + Angular (MEAN stack) with requireJS and using zombie for SEO
##Tech Stack##
- NodeJS with Express JS
- MongoDB with Mongoose layer
- Google cloud storage for CDN
##Frameworks##
- Express JS (4.11.0)
- AngularJS (1.3.8) with requireJS
- Zombie for generating pages for SEO
- hello.js (for social login)
- Gulp for task management
##Basic requirements for a site##
- Minimum number of http requests
- Single Page application in client side
- SEO support
- Logging - load my db queries, http requests received and error logs separately. This will be helpful for tracking
- CDN implementation - this is a common requirement for most of the projects. I have used Google Cloud storage as CDN for this project
- Configs for different environment
- Social Logins with regular signup/login
##What is included in this project##
- Server with nodeJS and expressjs framework. File:
server.js - MongoDB integration with Mongoose layer. File:
app/utils/database.js - Single Page application starter kit using AngularJS, RequireJS. File:
public/res/js/appModule.jsandpublic/res/js/appBootstrap.js - SEO support by rendering the pages in server side using Zombie framework. Reference: Seo for Single Page Applications File: in
server.jslook forapp_config.enableZombie - r.js optimizer integration for whole project using gulp. File:
build/build.js - r.js support for CSS also using require-css. You can load CSS on demand for the pages are you are in, instead of loading all CSS.
- Google cloud storage CDN integration for static resources and dynamic assets like user uploaded images through gulp task. File:
gulpfile.js - Complete social Logins using hello.js in client side. File:
public/res/js/app/pages/auth/authCtrl.js - Environment specific configurations in
configdirectory - Separate logging for DB queries, http requests, error etc, using winston and morgan. File:
app/utls/log.js - JSONP support for data from server. File:
server.jslook forrenderJson - Auth check for client side routes. example: "Edit your Profile" page in the seed project. Reference: Protecting routes in AngularJS. File:
public/res/js/routeResolve.jsandpublic/res/js/appRoutes.js - Dynamic meta content like page title, meta description, meta content for SEO. Reference: StackOverflow File:
public/res/js/appModule.jsand look forsetMeta. Configuration is mentioned inpublic/res/js/appRoutes.js - Session handling using MongoStore. File:
server.js - Global variables for client side templates like CDN url prefix for images, etc.. File:
public/res/js/appModule.jsand look for$rootScope.globals
##Steps to install##
- clone or download or fork this git repo
- Run
npm installto install dependencies - Run gulp task
./node_modules/gulp/bin/gulp.jsThis will build all necessary resources mentioned as inbuild/build.jsand add it todistdirectory. - The above gulp task will also start the server through this command:
node --debug serverand display the IP address and port in which it is started. Optionally, you can usesupervisorby uncommentingsupervisor -i "public,dist,views" --debug serverand commentingnode --debug serverinservertask - The above task will also listen for changes inside
publicfolder and re builds the resources whenever there is a change. livereload is enabled along with this task. - For checking SEO page(angularJS page rendered from server side), add
ngserver=trueto the page URL. ex:http://<ipaddress>:<port>/?ngserver=true. This will render html content of your root (/) page - file uploads - also handles heavy compression logic using
imagemin-jpeg-recompressfor jpeg files. Page:\home
##How to add new page##
- add new directory inside
public/res/app/pagesex:settings - add controller, service, css, template files as needed inside this directory
- Add the new route in
appRoutes.js, ex:/settings - Add the new module inside
build/build.js
###Production Deployment###
- In
gulpfile.jswe hav addedoptimizer=nonein the taskbuild. This will not minify the files when running the build for easy debugging during development. Remove thisoptimizer=nonewhile doing production deployment to minify the files - If you want to upload files to CDN, here I used Google Cloud storage, uncomment
gulp.task('default', ['uploadJS', 'uploadCSS']);ingulpfile.js. Make sure you add necessary keys and bucket names inapp.jsonconfigs. Running this task will upload CSS and JS files to the CDN bucket
###Coming soon###
- load combined view files instead of separate partials for each page
- Avoid adding logs to all folders. Currently logs are cumulatively added for lower levels. If log level is 5, all logs with levels < 4 will include logs of level 5. So it is getting duplicated.
- Control loading index.html for unhandled requests. Since I am using
*inroutes.js, if any the request is not handled,index.htmlwill be loaded. - Client side caching data using angular-cache
- samples for using bcrypt for password encryption, using mandrill API to send mail, newrelic implementation
###If SEO is not working###
- Add JS controller to build.js file. If you have imported css file in controller, SEO is not working