This tutorial uses Node.js, Express, Hogan.js, Parse, and Heroku to create an end-to-end web app that can sign-up, login, and logout users!
Node.js is a backend framework that is used to create a server. The server will pull data from the database, render pages, and route urls to the correct page. Routing is where you declare "/" or "/users" and whenever a request to "www.yourApp.com/" the "/" route is called, or "www.yourApp.com/users" the "/users" route is called.
Parse is a database that is in the cloud! You don't have to worry about configuring it, hosting it, or other difficult tasks. You just gra the application's keys and you can access your database with javascript!
Express is a backend framework that goes well with Node.js. Express can create scaffolding for your web app and express makes it extrememly easy to get your node app up and running with routes.
Hogan.js is a templating framework that we like to use to render a page on the server, then send the html file to the user. Templating is the idea that your html page may contain similar pieces of code, so rather than copying the same nav bar 10 times, you only write the nav bar code once, then include it in another file. Rendering also uses JSON objects to create html tags. For example, you can programmatically create a list of html elements with a simple for loop structure.
-
Download the zip file and extract it. If you have git installed, you can use:
git clone https://github.com/michaelbishoff/nodejs-Parse-user-auth.git
-
Download Node.js and install the dependencies:
cd nodejs-Parse-tutorial && sudo npm install
-
Create a Parse account and create a new Javascript app in Parse
-
Grab your Application ID & Javascript Key from your database
-
Click settings at the top
-
Click Keys on the left
-
Open
Procfile
and replace the placeholder text with the appropriate keys -
Execute the command in the
Procfile
without the "web:" prefix:
PARSE_APP_ID=APP_ID_PLACEHOLDER PARSE_JS_KEY=JAVASCRIPT_KEY_PLACEHOLDER npm start
Note: This initializes the environment variablesPARSE_APP_KEY
andPARSE_JS_KEY
, then starts the server. The env variables only exist while the server is running with this command. -
Navigate to localhost:3000 in a browser
You should be able to sign-up, login, and logout of an account using Node.js and Parse!
-
Install the express generator
npm install -g express-generator
-
Run
express myAppName --hogan
Note: The--hogan
means that it will use Hogan templating rather than the default Jade templating -
Follow the instructions that show up
-
Install dependencies:
cd myAppName && npm install
-
Run the app:
DEBUG=myAppName:* npm start
-
Navigate to localhost:3000 in a browser
You now have a basic app running with Node.js + Express! It uses Hogan templating to render the page. You still need to implement the Parse functionality, which you can find in this tutorial's code.
Heroku is a free to use tool that can be used to deploy your web app to a server with web hosting. This means that you can put your web app online and it will give you a url to access it.
The Official Node.js on Heroku Tutorial
Our Tutorial (a little more basic):
Assuming that you did everything in the Where to start? section above
-
Sign up for a Heroku account and make sure you have Node.js and npm installed (npm is bundled with Node.js).
-
Download the Heroku Toolbelt. This is a command line tool that is used to setup your app on heroku.
-
Execute
heroku login
and type in your Heroku account information. -
Run
heroku create
to create a new server to deploy your app to. This generates a random unique name for your app and url.
Note: this command takes a third optional argument which is the name of your app and url. For example, this tutorial used:
heroku create donut-tutorial
to create https://donut-tutorial.herokuapp.com/ -
Deploy your code to the webapp
git push heroku master
-
Open your web app in a browser
heroku open
Note: If you ever forget the name of your web app, running this command will open the heroku app (that is in the current directory) in a browser.