Realtime chat system with Node.js and the socket.io library
All dependencies are declared in the package.json file. They are not included in the zip and you will have to run npm install to get them.
- express.js
- gravatar
- socket.io
- ejs
Within the download you'll find the following directories and files, You'll see something like this:
nodejs-private-webchat/
├── public/
│ ├── css/
│ │ ├── bootstrap.icon-large.min.css
│ │ └── stylesheet.css
│ ├── img/
│ │ ├── glyphicons.png
│ │ ├── nodejslogo.png
│ │ └── unnamed.jpg
│ └── js/
│ │ ├── chat.js
│ │ └── moment.min.js
├── views/
│ ├── chat.html
│ └── home.html
├── app.js
├── config.js
├── routes.js
└── package.json
To begin running locally make sure you have Node.js installed and fork/clone this repo.
Navigate to directory
cd nodejs-private-webchat
Install dependencies
npm install
Start app on local server
node app.js
- Create an account, if you don’t have one already.
- Install the Heroku toolbelt for your operating system. It will give you access to the heroku command from a terminal window.
- Initialize an empty git repository (explained below)
- Push your code to Heroku. This will deploy it and give you a URL which you can share with your friends.
Creating a git repo
git init
Create a new empty text file named .gitignore with the following content:
node_modules/
Create a new empty text file named Procfile with the following content:
web: node app.js
Then commit the changes with these commands:
git add Procfile
git commit -m 'Added a procfile'
First you need to login to heroku from the command line tool:
heroku login
Add your ssh key if one is not auto generated.
heroku keys:add
Create a new heroku application from the code in this folder:
heroku create
finally, push code.
git push heroku master
Your application code was sent to heroku, where their servers will process your package.json file and install all libraries that your app needs. Do this every time you need to upload a new version of the code (you must have made a commit beforehand). All that is left, is to enable websockets so that our real-time chat can work
heroku labs:enable websockets
Open it in a tab in your default browser.
heroku open