Wednesday, 26 October 2016

Node development on CentOS for .Net devs

I'm about to start a new role which entails Node, Angular, Mongo and linux (CentOS) so ive set about learning the above. Quite a bit of a shift from the previous number of years which have been pretty much exclusively Microsoft and .Net. But im really excited about it and the new learning I need to embark upon. Today it was the turn of getting a CentOS development environment up and running on virtual box with npm, node and webstorm.

Creating the development environment

Install virtual box (5.1 at time of writing)
https://www.virtualbox.org/
download the dvd image of centOS (7 at time of writing)
https://www.centos.org/download/

Create a VM of the image,
On software selection i used KDE Plasma with internet tools and 
i used the KDE desktop with internet and KDE applications and development Tools
enable the network
create a user as well as set the super user password

To enable higher resolution
once set up, from the VM menu: device > insert guest additions CD image
this will act as if a cd was inserted into the VM
in the VBOXADDITIONS drive double click autorun.sh and enter your superuser password
reboot

Installing npm, node and webstorm

Within a terminal window
su -
yum install epel-release
yum install npm
npm --version
3.10.3
node --version
v6.7.0
exit

Download webstorm
http://www.jetbrains.com/webstorm/
Extract the folder to the place you want to install webstorm
double click webstorm.sh to install
remember to chose a dark theme ;-)

Create your first hello world node app with express

In a terminal (not as root)
cd /home/username/
mkdir code
cd code
mkdir express01
cd express01

npm init
take all the defaults
npm install express --save

Im not going to go into the the how to create a basic express app to echo something to the console and to the browser, there are so many tutorials about that out there.

Enjoy your new development environment.

Major learnings. I.e. Don't do this at work...


When you enter sudo for the first time you get the apt warning:

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.


The first time I created the hello world app from the guide above I used su for everything, including creating the folders and npm init. This resulted in files and folders that i could not write to from webstorm so i tried to fix the permissions with chmod. But I used it very very wrongly and the interwebs advised me to reinstall everything. Which as it happens, this time was not a big deal for me.
So what did i do?
Whilst i was su i think i ran:
chmod 777 /. -R
In powershell .\ is the current directory, I thought ./ would be the same in linux but i did a typo and so i ended up making all the files and folders (on the whole VM) 777 rather than just the new code folders. Apparently this is very hard to fix.
The symptom is you type the command su - you get the error:
su -
su: cannot set groups: Operation not permitted

It can make things rather difficult if you cant get root access anymore.

Should it be this easy to screw your entire VM? or was there actually an easy fix? if you know id love to hear about it.




No comments:

Post a Comment