Sign inSign up

garethrobertlee/p23

By garethrobertlee

Updated almost 11 years ago

A

Image
0

3.5K

garethrobertlee/p23 repository overview

Alt Hackathon Starter Dependency Status Build Status Analytics

Join the chat at https://gitter.im/sahat/hackathon-starter Thinkful Pair on Node

Live Demo: http://hackathonstarter.herokuapp.com

Jump to What's new in 3.1.0?

A boilerplate for Node.js web applications.

If you have attended any hackathons in the past, then you know how much time it takes to get a project started: decide on what to build, pick a programming language, pick a web framework, pick a CSS framework. A while later, you might have an initial project up on GitHub and only then can other team members start contributing. Or how about doing something as simple as Sign in with Facebook authentication? You can spend hours on it if you are not familiar with how OAuth 2.0 works.

When I started this project, my primary focus was on simplicity and ease of use. I also tried to make it as generic and reusable as possible to cover most use cases of hackathon web apps, without being too specific. In the worst case you can use this as a learning guide for your projects, if for example you are only interested in Sign in with Google authentication and nothing else.

Chances are you do not need all authentication methods or API examples. As of Hackathon Starter 2.1 it is possible to selectively check which authentication methods you need by running node setup.js.

Modern Theme

Flatly Bootstrap Theme

API Examples

Hackathon Starter Generator

Table of Contents

Features

  • Local Authentication using Email and Password
  • OAuth 1.0a Authentication via Twitter
  • OAuth 2.0 Authentication via Facebook, Google, GitHub, LinkedIn, Instagram
  • Flash notifications
  • MVC Project Structure
  • Node.js clusters support
  • Rails 3.1-style asset pipeline by connect-assets (See FAQ)
  • LESS stylesheets (auto-compiled without any Gulp/Grunt hassle)
  • Bootstrap 3 + Flat UI + iOS7
  • Contact Form (powered by Mailgun, Sendgrid or Mandrill)
  • Account Management
  • Gravatar
  • Profile Details
  • Change Password
  • Forgot Password
  • Reset Password
  • Link multiple OAuth strategies to one account
  • Delete Account
  • CSRF protection
  • API Examples: Facebook, Foursquare, Last.fm, Tumblr, Twitter, Stripe, LinkedIn and more.

Prerequisites

  • MongoDB
  • Node.js
  • Command Line Tools
  •  Mac OS X: Xcode (or OS X 10.9 Mavericks: xcode-select --install)
  •  Windows: Visual Studio
  •  Ubuntu: sudo apt-get install build-essential
  •  Fedora: sudo dnf groupinstall "Development Tools"
  •  OpenSUSE: sudo zypper install --type pattern devel_basis

Note: If you are new to Node or Express, I recommend to watch Node.js and Express 101 screencast by Alex Ford that teaches Node and Express from scratch. Alternatively, here is another great tutorial for complete beginners - Getting Started With Node.js, Express, MongoDB.

Getting Started

The easiest way to get started is to clone the repository:

# Get the latest snapshot
$ git clone https://github.com/sahat/hackathon-starter.git myproject
$ cd myproject
$ git remote rm origin

# Install NPM dependencies
$ npm install

$ node app.js

Note: I highly recommend installing Nodemon. It watches for any changes in your node.js app and automatically restarts the server. Once installed, instead of node app.js use nodemon app.js. It will save you a lot of time in the long run, because you won't need to manually restart the server each time you make a small change in code. To install, run sudo npm install -g nodemon.

Generator

Hackathon Starter Generator is tighly coupled to the project code. As soon as you start changing and moving things around, it will probably no longer work as expected. That is why it's best to use when you first download the project.

Currently it supports switching between SendGrid, Mailgun and Mandrill email services and adding a Node.js cluster support.

To get started, run: node setup.js.

Note: Generator has a "destructive" behavior, it will physically modify your code. There is no undo action. To be on a safe side, always commit your code to Git, so you could go back and revert the changes.

Obtaining API Keys

To use any of the included APIs or OAuth authentication methods, you will need to obtain appropriate credentials: Client ID, Client Secret, API Key, or Username & Password. You will need to go through each provider to generate new credentials.

Hackathon Starter 2.0 Update: I have included dummy keys and passwords for all API examples to get you up and running even faster. But don't forget to update them with your credentials when you are ready to deploy an app.

- Visit [Google Cloud Console](https://cloud.google.com/console/project) - Click on the **Create Project** button - Enter *Project Name*, then click on **Create** button - Then click on *APIs & auth* in the sidebar and select *API* tab - Click on **Google+ API** under *Social APIs*, then click **Enable API** - Next, under *APIs & auth* in the sidebar click on *Credentials* tab - Click on **Create new Client ID** button - Select *Web Application* and click on **Configure Consent Screen** - Fill out the required fields then click on **Save** - In the *Create Client ID* modal dialog: - **Application Type**: Web Application - **Authorized Javascript origins**: http://localhost:3000 - **Authorized redirect URI**: http://localhost:3000/auth/google/callback - Click on **Create Client ID** button - Copy and paste *Client ID* and *Client secret* keys into `config/secrets.js`

Note: When you ready to deploy to production don't forget to add your new url to Authorized Javascript origins and Authorized redirect URI, e.g. http://my-awesome-app.herokuapp.com and http://my-awesome-app.herokuapp.com/auth/google/callback respectively. The same goes for other providers.


- Visit [Facebook Developers](https://developers.facebook.com/) - Click **My Apps**, then select **Add a New App* from the dropdown menu - Select **Website** platform and enter a new name for your app - Click on the **Create New Facebook App ID** button - Choose a **Category** that best describes your app - Click on **Create App ID** button - In the upper right corner click on **Skip Quick Star** - Copy and paste *App ID* and *App Secret* keys into `config/secrets.js` - **Note:** *App ID* is **clientID**, *App Secret* is **clientSecret** - Click on the *Settings* tab in the left nav, then click on **+ Add Platform** - Select **Website** - Enter `http://localhost:3000` under *Site URL*

Note: After a successful sign in with Facebook, a user will be redirected back to home page with appended hash #_=_ in the URL. It is not a bug. See this Stack Overflow discussion for ways to handle it.


- Go to [Account Settings](https://github.com/settings/profile) - Select **Applications** from the sidebar - Then inside **Developer applications** click on **Register new application** - Enter *Application Name* and *Homepage URL* - For *Authorization Callback URL*: http://localhost:3000/auth/github/callback - Click **Register application** - Now copy and paste *Client ID* and *Client Secret* keys into `config/secrets.js`
- Sign in at [https://apps.twitter.com/](https://apps.twitter.com/) - Click **Create a new application** - Enter your application name, website and description - For **Callback URL**: http://127.0.0.1:3000/auth/twitter/callback - Go to **Settings** tab - Under *Application Type* select **Read and Write** access - Check the box **Allow this application to be used to Sign in with Twitter** - Click **Update this Twitter's applications settings** - Copy and paste *Consumer Key* and *Consumer Secret* keys into `config/secrets.js`
- Sign in at [LinkedIn Developer Network](http://developer.linkedin.com/) - From the account name dropdown menu select **API Keys** - *It may ask you to sign in once again* - Click **+ Add New Application** button - Fill out all the *required* fields - **OAuth 2.0 Redirect URLs**: http://localhost:3000/auth/linkedin/callback - **JavaScript API Domains**: http://localhost:3000 - For **Default Application Permissions** make sure at least the following is checked: - `r_basicprofile` - Finish by clicking **Add Application** button - Copy and paste *API Key* and *Secret Key* keys into `config/secrets.js` - *API Key* is your **clientID** - *Secret Key* is your **clientSecret**
- Visit the **Account** section of your Venmo profile after logging in - Click on the **Developers** tab - Then click on the [new](https://venmo.com/account/app/new) link next to **Your Applications (0)** - Fill in the required fields: *App Name* and *What Will The App Be Used For?* - For **Web Redirect URL** enter: http://localhost:3000/auth/venmo/callback - Hit **Create** button - Back on the **Developers** tab click on **view** link next to **Your Applications (1) new** - Copy and paste **ID** and **Secret** keys into `config/secrets.js`
- [Sign up](http://stripe.com) or log into your [dashboard](https://manage.stripe.com) - Click on your profile and click on Account Settings - Then click on [API Keys](https://manage.stripe.com/account/apikeys) - Copy the **Secret Key**. and add this into `config/secrets.js`
- Visit [PayPal Developer](https://developer.paypal.com/) - Log in to your PayPal account - Click **Applications > Create App** in the navigation bar - Enter *Application Name*, then click **Create app** - Copy and paste *Client ID* and *Secret* keys into `config/secrets.js` - *App ID* is **client_id**, *App Secret* is **client_secret** - Change **host** to api.paypal.com if you want to test against production and use the live credentials
- Go to [foursquare for Developers](https://developer.foursquare.com/) - Click on **My Apps** in the top menu - Click the **Create A New App** button - Enter *App Name*, *Welcome page url*, - For **Redirect URI**: http://localhost:3000/auth/foursquare/callback - Click **Save Changes** - Copy and paste *Client ID* and *Client Secret* keys into `config/secrets.js`
- Go to http://www.tumblr.com/oauth/apps - Once signed in, click **+Register application** - Fill in all the details - For **Default Callback URL**: http://localhost:3000/auth/tumblr/callback - Click **✔Register** - Copy and paste *OAuth consumer key* and *OAuth consumer secret* keys into `config/secrets.js`
- Go to http://steamcommunity.com/dev/apikey - Sign in with your existing Steam account - Enter your *Domain Name*, then and click **Register** - Copy and paste *Key* into `config/secrets.js`
- Go to https://sendgrid.com/user/signup - Sign up and **confirm** your account via the *activation email* - Then enter your SendGrid *Username* and *Password* into `config/secrets.js`
- Go to http://www.mailgun.com - Sign up and add your *Domain Name* - From the domain overview, copy and paste the default SMTP *Login* and *Password* into `config/secrets.js`
- Go to http://mandrill.com - Sign up and add your *Domain Name* - From the dashboard, click on *Get SMTP credentials* - Copy and paste the default SMTP *Login* and *Password* into `config/secrets.js`
- Go to https://test.bitgo.com/ - Sign up for an account. - Once logged into the dashboard, go to the top right selector and click 'account settings' - Under the developers tab, create your access token and copy and paste it into `config/secrets.js`
- No account is necessary; by default the Bitcoin Testnet is accessible via the free Bitpay Insight API. - You can use real bitcoins (be careful!) by setting BITCORE_BITCOIN_NETWORK environment variable to 'livenet', or edit `config/secrets.js` - You can use bitcore client-side-only by first building js files for the browser, see http://bitcore.io/guide/browser.html - You can build some altcoin projects by editing the Network and using your own full node http://bitcore.io/guide/networks.html - You can optionally use your own Bitcoin (or altcoin) full node running the Insight API, see https://github.com/bitpay/insight-api

Project Structure

NameDescription
config/passport.jsPassport Local and OAuth strategies, plus login middleware.
config/secrets.jsYour API keys, tokens, passwords and database URL.
controllers/api.jsController for /api route and all api examples.
controllers/contact.jsController for contact form.
controllers/home.jsController for home page (index).
controllers/user.jsController for user account management.
models/User.jsMongoose schema and model for User.
public/Static assets (fonts, css, js, img).
public/js/application.jsSpecify client-side JavaScript dependencies.
public/js/main.jsPlace your client-side JavaScript here.
public/css/main.lessMain stylesheet for your app.
public/css/themes/default.lessSome Bootstrap overrides to make it look prettier.
views/account/Templates for login, password reset, signup, profile.
views/api/Templates for API Examples.
views/partials/flash.jadeError, info and success flash notifications.
views/partials/header.jadeNavbar partial template.
views/partials/footer.jadeFooter partial template.
views/layout.jadeBase template.
views/home.jadeHome page template.
.travis.ymlTravis CI integration.
app.jsMain application file.
setup.jsTool for removing authentication providers and other things.

Note: There is no preference how you name or structure your views. You could place all your templates in a top-level views directory without having a nested folder structure, if that makes things easier for you. Just don't forget to update extends ../layout and corresponding res.render() paths in controllers.

List of Packages

PackageDescription
asyncUtility library that provides asynchronous control flow.
bcrypt-nodejsLibrary for hashing and salting user passwords.
bitcoreBitcoin library.
bitcore-explorersBlockchain APIs for bitcore.
bitgoMulti-sig Bitcoin wallet API.
cheerioScrape web pages using jQuery-style syntax.
clockworkClockwork SMS API library.
connect-assetsCompiles LESS stylesheets, concatenates & minifies JavaScript.
connect-mongoMongoDB session store for Express.
cssoDependency for connect-assets library to minify CSS.
expressNode.js web framework.
body-parserExpress 4 middleware.
cookie-parserExpress 4 middleware.
express-sessionExpress 4 middleware.
morganExpress 4 middleware.
multerExpress 4 middleware.
compressionExpress 4 middleware.
errorhandlerExpress 4 middleware.
method-overrideExpress 4 middleware.
serve-faviconExpress 4 middleware offering favicon serving and caching.
express-flashProvides flash messages for Express.
express-validatorEasy form validation for Express.
fbgraphFacebook Graph API library.
github-apiGitHub API library.
jadeTemplate engine for Express.
lastfmLast.fm API library.
instagram-nodeInstagram API library.
lessLESS compiler. Used implicitly by connect-assets.
lobLob API library
luscaCSRF middleware.
mongooseMongoDB ODM.
node-foursquareFoursquare API library.
node-linkedinLinkedIn API library.
nodemailerNode.js library for sending emails.
passportSimple and elegant authentication library for node.js
passport-facebookSign-in with Facebook plugin.
passport-githubSign-in with GitHub plugin.
passport-google-oauthSign-in with Google plugin.
passport-twitterSign-in with Twitter plugin.
passport-instagramSign-in with Instagram plugin.
passport-localSign-in with Username and Password plugin.
passport-linkedin-oauth2Sign-in with LinkedIn plugin.
passport-oauthAllows you to set up your own OAuth 1.0a and OAuth 2.0 strategies.
paypal-rest-sdkPayPal APIs library.
requestSimplified HTTP request library.
stripeOffical Stripe API library.
tumblr.jsTumblr API library.

Tag summary

Content type

Image

Digest

sha256:565c76eb9

Size

296.9 MB

Last updated

almost 11 years ago

docker pull garethrobertlee/p23