Server - hosted on Heroku Client - including performance patches
Once you’ve built your server and tested it locally, you can host it online and have clients connect to it remotely using a hosting service like Heroku. Here are some steps on how to host your Node server on Heroku:
First, create a Github repo for your project files and sign up with Heroku. Once you’ve signed up, download the command line interface tools here.
max-socketIO—local-server.js
file we used earlier and get it ready for remote hosting.
max-socketIO-sever.js
file. Rename it max-socketIO—heroku-sever.js
just for clarity.package.json
file by running npm init
in this directory.npm install express --save
and npm install socket.io --save
The MaxAPI will only be used by our client patch, so the server won’t need it.package.json
file and your should now see a section that lists you’re dependencies.start
script that specifies which file Node will run once Heroku fires up the server. For this example, you should add the following into your package.json
file:
"scripts":{
"start": "node max-socketIO-heroku-server.js"
},
npm install
.heroku local web
in your terminal..gitignore
. This file will keep track of items in our directory that we don’t want pushed to our git repo. Ideally, we don’t want any copies of our node modules or build artifacts being hosted on Github, so open the .gitignore
file and add:
/node_modules
npm-debug.log
.DS_Store
/*.env
heroku login
and press any key to open a browser window. Enter your login credentials when prompted.heroku create
to publish your app to Heroku.heroku apps:rename
followed by the new name that you’d prefer, the –app flag and the old name assigned to your app by Heroku. Here’s an example:
heroku apps:rename noderemoteworkshop --app damp-reef-50960