Tag Archives: Heroku

Use MongoDB with a NodeJS Application on Heroku


Use MongoDB with a Node.js Application on Heroku
By Igor Ribeiro Lima

sshot-10645.png
Igor Ribeiro Lima ( @igorribeirolima ) Tutorials expressJS , heroku , javascript , mongoDB , node.js On this blog post I’ll use a JS MVC ToDo List to show you step by step how to deploy an application using Node.js with Express and Mongoose on Heroku. There are many ToDo app examples over there. All of them are basically client side source code, which means you have to create a server file in order to deploy it to Heroku. A good news is this file is already created, and the another good new is that server file can be used in almost all ToDo apps listed there. This file gives you the flexiblity to use any JavaScript MVC from your choice. I’m gonna use the one built by AngularJS framework.
Based on this MVC AngularJS ToDo List, I created a new github repository to be easier to deploy it on Heroku. If you’re unfamiliar with those technologies, now would be an excellent time to go through this great start. And for you, developer, who’s familiar with JavaScript, for sure it’ll not be hard. Go check it out!

Setting up a free account on Heroku and MongoLab

Before I get into the code and walk you through it, I wanted to talk about how to create your free account on Heroku and set it up: (i) first of all sign up, (ii) after that create your first app and (iii) then register and add a public SSH key to your account. You can check this guide out for further details about generating SSH keys.
The next step is to have a Mongo database running. It’s NOT required but it’s a necessary step to test it locally before deploying. To simplify let’s use a MongoDB as a Service using MongoLab. Feel free to sign up and create your own database.

Running the example locally

The source code is available on my GitHub, clone it with:


git clone git@github.com:igorlima/deploy-express-with-mongoose-on-heroku.git

To run it locally, install all dependencies needed with npm install. And set a new environment variable: MONGOLAB_URI. It should contain all the MongoDB connection information needed to connect to your database. You may also specify several more parameters in the uri depending on your environment. In this example, we are gonna use the following standard: mongodb://username:password@host:port/database

I’m gonna share my credential here. Feel free to use it while you’re learning. After that, create and use your own credential. Thanks.

For Mac/Linux users, you can simply type:


export MONGOLAB_URI="mongodb://example:example@ds053312.mongolab.com:53312/todolist"

For Windows users, do:


SET MONGOLAB_URI="mongodb://example:example@ds053312.mongolab.com:53312/todolist"

After setting up this environment variable, run via terminal node server.js. It should be available at the port 5000, then open any browser and reach http://localhost:5000/.

Deploying on Heroku

You can easily use a git repo to deploy to Heroku, you just need to add a new remote git repository by using the git remote add command on the terminal. To know your app remote URL you have to go to your Dashboard, click on the app you have created in the session above, then click on Settings link. You’ll be able to see the Git URL, copy and use it in the command below:


git remote add heroku git:

Now that we have everything in order, go ahead and push to Heroku!


git push heroku HEAD:master

Notice this example app has a file named Procfile. It’s a text file in the root directory to explicitly declare what command should be executed to start your app. The Procfile in this example app you deployed looks like this:


web: node server.js

I wanna take a moment and mention Heroku tool belt. A command line utility to access Heroku Platform API for creating/renaming apps, running one-off dynos, taking backups, and configuring add-ons. Check out this blog post to know all steps required to deploy to Heroku by using Heroku tool belt.

Adding a MongoDB add-on

Now it’s time to add the MongoLab add-on. To do that you can simply go to your Dashboard, click on the app just created by you, open the Resources tab and then add a new add-on clicking on EDIT or PLUS button under Add-ons session. See images below:
IMG_0890_zpstuzzdx0b.png
IMG_0891_zpsudvl1cak.png

There many MongoDB services, I choose MongoLab because one reason: it’s free. To find more add-ons, feel free to see all at this link.

The MongoLab add-on contributes one config variable to your Heroku environment: MONGOLAB_URI. This variable is a URI containing all the MongoDB connection information needed to connect to your database.

Most client libraries support using the URI directly. However, some will require pulling the components of the URI apart.

Happy browsing

We’re finally at the part that we’ve wanted this entire time. Seeing the application in browser! Go ahead and visit that in browser: http://
It’s magic! We have our MVC ToDo List app in the browser just like we wanted.
AngularJS_bull_TodoMVC_and_Deploy_a_NodeJS_application_with_MongoDB_add-on_on_Heroku_zps3irnkmjb-556x500.png

Conclusion

That’s it folks. I hope you learned how simple and fun is to deploy an Express app with Mongoose on Heroku. In the meantime, go through the Heroku Node docs and drop a line if you’d like to see more blog posts about any other Heroku things or other services similar to Heroku. Thanks for reading!

How to Build A Slackbot + Deploy an App to Heroku for Absolute Beginners


via The npm Blog — How to Build A Slackbot + Deploy an App to Heroku….

Back in ye olde days of the internet, there was IRC (Internet Relay Chat), a chat network with channels and servers for every microcosm in the world. Folks would make these little bots or services — they’d greet you when you joined a channel, played trivia, Uno and other chat-based games with you. Unfortunately, if you wanted to make one yourself, you likely needed some knowledge of Perl, client-server architecture and a handful of Unix commands.

Today, most will opt for a more aesthetic alternative to IRC. Namely, Slack — a chat-based team communication tool. The best part? You can create a Slackbot with substantially fewer roadblocks.

I’ll try not to make assumptions on the technologies you may or may not have on your machine here. So let’s go ahead and start from scratch. If you already have any or all of following downloaded, you’re ahead of the game!

Deploy WebSphere Liberty Profile applications to Bluemix using Maven


via RETHINK IT.

The IBM WebSphere Application Server Liberty Buildpack is used to deploy Liberty applications to Bluemix and other Cloud Foundry-based platforms. The Liberty buildpack deploys compiled artifacts such as .war or .ear files, server packages (.zip files), or server directories. In combination with thecloudfoundry-maven-plugin and the liberty-maven-plugin you’re able to integrate all build, test and deployment steps with Maven.

This blog post will show how you can setup the Liberty Profile Server, run and test your application on it, create a packaged server and deploy it to Bluemix – All done with Maven.

An alternative approach would be to deploy the source and execute a Maven build on the Bluemix server using the Heroku buildpack for Java applications as described here.

3 Simple Methods to Start Debugging NodeJS Application on Heroku


via 3 Simple Methods to Start Debugging Node.js Application on Heroku | AppDebug – Node.js Debugging Made Easy.

At the moment, AppDebug is available only on Heroku, but we wanted to give non-Heroku users the chance to experiment with the application and get their feedback about it. The following blog post describes 3 different methods to get started with AppDebug. For your convenience, we stated at the beginning of each method, who would be the ideal audience to use it.

The first thing you’ll have to do is to sign up on our homepage (wait, don’t leave now! there’s a signup dialog at the bottom of this post :) ).

Use MongoDB with a NodeJS Application on Heroku


via Use MongoDB with a Node.js Application on Heroku | Scotch.

On this blog post I’ll use a JS MVC ToDo List to show you step by step how to deploy an application using Node.js with Express and Mongoose on Heroku. There many ToDo app examples over there. All of them are basically client side source code, which means you have to create a server file in order to deploy it to Heroku. A good news is this file is already created, and the another good new is that server file can be used in almost all ToDo apps listed there. This file gives you the flexiblity to use any JavaScript MVC from your choice. I’m gonna use the one built by AngularJS framework.

Based on this MVC AngularJS ToDo List, I created a new github repository to be easier to deploy it on Heroku. If you’re unfamiliar with those technologies, now would be an excellent time to go through this great start. And for you, developer, who’s familiar with JavaScript, for sure it’ll not be hard. Go check it out!

npm Private Modules with Heroku


via npm Private Modules with Heroku | Piggybank Blog.

Yesterday npm released a feature called private modules. It let’s you publish to their module registry (npmjs.com) but keep your modules private. The old way of achieving private modules without running your own registry was convoluted, didn’t work well and required you commit and push your app tokens into your source code (gross). The new way, from npm, let’s you publish private modules just like normal modules and simply copy and paste your token into Heroku’s environment variables to keep it safe.

The general steps are:

  1. Sign up for private modules if you haven’t already yet (it’s $7 a month, why haven’t you?)
  2. Login to npm from the CLI
  3. Publish your private module to npm
  4. Setup .npmrc files for your project folders
  5. Create an environment variable on Heroku

NodeJS For Beginners. Deploy Your Blog to Heroku


via Node.js For Beginners. Deploy Your Blog to Heroku – How To Node – NodeJS.

Error pages are not what typically appear on your screen when you’re surfing the web, but when it happens it’s so annoying! To see how servers work from within, we will build a simple web server by ourselves. We will use Node.js as a server part technology for that task. Then we’ll use Heroku cloud application platform to turn this local server into a world wide server.