Wednesday, January 8th, 2019
So, I've been working no a ChromeBook for the last while, I really like the simplicity. After being trapped in corporate world of ancient windows versions, I needed to learn a new OS just to continue using Windows, so when I found out that I could create linux machines on a Chromebook, I was sold, I thought I'll try that, and have for the last few weeks been doing a little development on my little chromebook, with just 4GB of RAM.
While it worked, it was painfully slow. Sure, opening gazillions of chrome tabs it was enough, starting up and shutting down was great, but the Linux virtual machine it starts only has 2GB of RAM, I'd hoped it was going to be so vastly more efficient than Windoze that 2GB would do it, but eh no, it didn't, it ran, but the IDE lagged as I was typing, the whole rhythm of development was upset. Word was I was going to need to shell out for a 16GB laptop, whatever the operating system. Worse, whilst I could get a windoze one for under €1,000 only Linux I can find is €1,299 from Dell and a ChromeBook, I need to jump to a PixelBook, at around €2,000 - That's a lot more than I wanted to spend on my experiment.
So I got on the phone to my mate and hero, Kieron, at Castle Computers. I think he thought I was on again about getting him to climb Croagh Patrick again, so it was out of a desire to get me off the phone before I mentioned it, that he agreed to lend me a 16GB ThinkCentre Workstation, to have a whack at it. It would be running Windoze, but I could create a Linux virtual machine on it using Hyper-V, sounded good.
So there I am setting it up, figure out HyperV just needs to be enabled, coz I'm on Windows Pro... Am I breaking the law already? Technically speaking you are not permitted to borrow someone's windoze license, and if this all works out, am I going to need to buy Windows pro? Got the Hyper-V working, got a Linux Machine started, while it was doing that I downloaded all the windows packages for MEAN, Linux screen is wrong size, apparently there is something I can do in the terminal to fix that, bloody hell, the terminal is slow to start, kick off Windoze install while I wait for it, and what d'ya know, I get the mean stack deployed on Windows before I can get the HyperV terminal started. Sod it, looks like I am going windoze, there's a bit of messing around, I need to run my IDE as an administrator to get it to work, nice, so if I write a program that accidentally tries chewing up my machine, it will have full admin privileges to do it, but hey, it all works, and it is SOOO much faster than my Chromebook, I think, I might just stick with it.
And then I woke up this morning, and thought, has to be a better way, I'd heard somewhere I could run Ubuntu on a USB Drive, so I dug out a €10 16GBUSB Drive from my bottom drawer, and had a whack at it. I've never before installed an operating system in my life, but hears how it went.
So I followed the instructions here: https://tutorials.ubuntu.com/tutorial/tutorial-create-a-usb-stick-on-windows#0 couldn't have been easier, basically :-
That was too easy, no way it is going to work, but bloody hell, it did. I powered down my windows machine, started it up again, it recognized the bootable USB Device, and asked me did I want to start Ubuntu, or did I want to do a permanent install on to my machine... Thought Kieron might not be impressed with me if I do that, so started Ubuntu, and voila, I have a fully functional Ubuntu machine.
I got the hint here, to click on System to configure my Wifi, connected the machine to the internet, and I could start installing!
Note, the installation below will be transient on the USB Drive, it's worthwhile to go through and install on the USB just to try it out, but if you are sure you want to use Ubuntu, you might go ahead and install Ubuntu Permanently, it was easier than I though, and my notes are here.
So I got the hints from here. Three commands and I'm done!
sudo apt-get install curl
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install nodejs
To verify, a simple "node -v" command tells me that node 12.14.1 has been installed
So I get some hints from here. 9 commands, but it's all copy paste and I'm done.
The "mongod --version" command tells me that the Mongo service v4.2.2 is installed.
The "mongo --version" command tells me that the Mongo shell v4.2.2 has been installed.
Not strictly necessary, but Mongo DB Compass provides a user interface to interact with the mongo database, I got the hint on how to install here, basically followed the link to the .DEB file, downloaded and opened it. Now I can start it from the start menu, or run "mongodb-compass" in the terminal window. Good to go on Mongo!
So it's possible to go old school and operate with a basic text editor, but really you need an IDE. Visual Studio my first real IDE, until I went through a religious conversion away from Microsoft and proprietary technologies. As my first IDE in the open source world I used eclipse, before upgrading to intelliJ IDEA which was a huge productivity improvement over eclipse and reasonably workable. As I progressed into doing Single Page Application development though, I was going to need to pay for their WebStorm variant, which was enough to set me off on the upheaval that is switching IDE's. When looking around, I was very pleased indeed to discover Visual Code, a free editor from Microsoft, builton NodeJS technologies. Honestly, it was more than 12 years since I'd opened Visual Studio, and for the first time I had an editor again that that felt like I was using it because it was simply the best tool to get the job done. Installation is a breeze. Go to here, download and open the .DEB file.
You might also want to start up Visual Code, and go to File, Preferences, Extensions, and install Angular Essentials. Note if you are coming from an IntelliJ world, you might wonder why things aren't saving, the "AutoSave" is toggled on and off from the File menu in Visual Code.
Version Control is technically optional, but really, seriously, if you're ever going to put anything into production, it's not optional at all. If you are going to share code with anybody else, it not optional. If you ever want to do anything complex, it is not optional. If you have used other version control systems, then it might take a while to get your head around GIT as it works very differently, but once you do, you would not even consider for a moment going back to an old school centralized version control system. Indeed, when you create your first angular project, it will automatically create your git repository. If you are not already familiar with Git, well worthwhile to do some tutorials, atlassian offer some good ones here.
You can also create free accounts to store your source code in the cloud. The 2 big providers are GitHub or Atlassian BitBucket. If you go with GitHub, you'll be in good company, seems most of the largest open source projects are shared on there. Github was however taken over by Microsoft in 2018, so who knows if they will all stay. Atlassian BitBucket will put you in good stead for working in the commercial world, as it is the first choice for most organisation I know of, primarily due to the cost of acquiring GitHub licenses being prohibitively high, that may change with the Microsoft Acquisition. Either way, all we are talking about are different Web Interfaces for your online repositories, GIT the actual version control mechanism is identical between the two, happily installing it is a breeze.
sudo apt install git-all
That's it, your ready to go with Git!
Installing Angular, besides making the Javascript libraries available, will also create a script for you, which provides alls orts of goodies such as making it easier to create new projects, components etc., as well as making it much easier to serve your project.
Note, first time I tried that, the "ng" command is not working, I get an error "The program 'ng' is currently not installed. You can install it by typing: sudo apt install ng-common". With a fair amount of messing, I figured out the issue was I had run the NPM command without using the sudo option in front of it, so make sure you do use sudo.
Couldn't be simpler, just type in a terminal window :
It will ask do you want to add routing, ultimately you will, but for demonstration purposes doesn't matter if you do or not. See here for more details on the ng new command.
Express is "just" a javascript library, so no seperate install necessary for it, you just install the script into your project, i.e.
We're good to go, still in the "my-new-project" directory, enter "ng serve", it builds and starts a node development server. Point your browser to http://localhost:4200 and you should see your app running there, happy days. One of the wonderful things about the ng serve command is that it will scan your code for changes, and if it sees any it will incrementally recompile and reload your changes. When I tried development with the chromebook, ng serve took a full 45 seconds or so to build and serve the first time, however when there where changes, it picked them up and restarted in a timely fashion, even with only 2GB of memory available!
For now though, hit Ctrl-C and stop that.
Try typing "git status", and you'll see the package.json has been updated, as we added express, but more importantly that we are already working in a git repository that angular created for us!
You need an extra bit of Angular Wizardry to run from inside of your IDE, well, inside of Visual Code anyways. In the my-new=project folder, run the command :
Open up Visual Code, select "File" / "Open Folder" from the menu, and open the my-new-project folder
Select "Terminal", "New Terminal" from the menu, and then enter "ng serve" inside the new terminal window, you will see the application start, and indeed you can again point your browser to http://localhost:4200 to see the app. One of the great advantages of the IDE though is debugging. The days are gone where we added log statements everywhere as we tried to guess what's going on, the debugger now lets us stop and inspect and step through code etc, way more powerful, so let's get it going!
First in Visual Code, got to menu "File, Preferences, Extensions" and make sure that the "Chrome Debugger Extension" is installed and enabled, it should be by default. You might want to work through this quick tutorial to get started, which includes debugging, but quickly, to debug:
That's it, your up and running with a complete MEAN stack development environment, go create something wonderful with it!
Ok, so after setting it all up and getting it working, I power off the machine, take my USB Drive with me and go do something in the real world. Come back the next day to create something wonderful, and it's gone. The whole thing has reset itself. There may well be a way to make it stick around, but a quick google didn;t find it for me, I was sufficiently pleased with the environment though, I just went ahead and installed Ubuntu on to the machine permanently. I've never installed an operating system of any sort before this, have to say, hats off to the canonical folks for making it pretty easy to do. I did spend some time messing around with setting up disk partitions, because I wanted option to get back to windoze, but other than that was a doddle, following same instructions as above.