Recently as more people learn Node.js and various other software services I have come across more queries revolving around running them publicly on the internet. This ends up being a problem as a lot of people getting into Node.js are front end or beginner developers, not that there is anything wrong with this.
Correctly setting up a server to run a Node.js app is not particularly difficult, it just involves a bit more knowledge than most beginners have. I’m going to split the problem into a few small chunks to make it easier to digest, but will start with the basics of getting a server set up and move on from there.
Buying a Server
With the advent of cheap VPS servers this is an easy undertaking and you can get a server set up within a few minutes of parting with your cash. OVH are a great example of this and the server I will be demoing my guide on cost me £4.99 a month and was set up within 20 minutes of me paying.
Updating and Initial Setup
To make things a little easier we will be using Ubuntu for this guide, the upshot being you don’t need to compile anything as it can be testing at the best of times. So best practise when starting to use any server is to update your packages and install sudo if its not on there already.
apt-get install sudo
This will upgrade all the software on your server and install sudo – this will allow you to run commands as an administrator whilst being logged in as a user.
Don’t do EVERYTHING as root
You may have noticed we have been able to do installation on the system up until now without any special permissions, we should still be running as the root user at this point, big mistake, we could accidently type something like
rm -rf / and bring our entire system down. To fix this we need to get sudo set up, this application grants the powers of root to the user for the duration of a command.
To get sudo setup we first need to create a user, to do this just type in
adduser [your username] and fill out the information you are asked for. Word of warning, do not put any spaces in your name, try something simple like first initial – surname (lgold is an example for me).
Once you have done this you need to set a password for your new user, type in
passwd [your username] and enter a password for your user.
You are now ready to give them root powers, type in the following to put your user into the admins group:
usermod -a -G admins [your username]. This will get you set up with the ability to get root permissions.
You can now log out of your server and log back in. When asked for a username type in your new username and password and your in! Just to test that this has worked try typing
apt-get update, you should get some complaints about permission and will not be allowed to update. Now try
sudo apt-get update and type in your password when asked, you should now get a stream of information about updates.
More to come
I’ll finish here for the moment as there was quite a bit to take in there, more to come and I will link from this article.
This post has been viewed 1296 times.