I love it

I still loath JavaScript (as I suck at it) but I found a new love in node.js (hey I know it’s 2017 and it has been around forever) but having spent the last 15 years developing back-ends for the web using .net, which I still defend to the bitter end (as my colleagues will attest to) 😉 I have to admit the beautiful simplicity in node js.

how about this

var http = require('http');

//create a server object:
http.createServer(function (req, res) {
  res.write('Hello World!'); //write a response to the client
  res.end(); //end the response
}).listen(8080); //the server object listens on port 8080

stick this in a .js file

if you have node installed you can run this from a terminal (console or power shell on windows)

$ node yourfile.js

Baaam! You have a web server running, listening to a specific port and responding to a request in 5 lines of code. Even I can see the beauty in that.

I actually built my first senor develop blog using node and the express js framework. The whole solution is under 500 lines of code!!! (not counting css). and naturally not counting the black hole that is npm_modules. For anyone of you that is new to node this is where all the dependencies go and it can get insanely large, as each your dependencies e.g express has its own dependencies and it will grow exponentially.

Another problem I encountered once selecting node as my back-end was where to host it. Shared hosting like the one offered from where I purchased my domain can’t run node apps. I did not want a virtual machine or a dedicated machine for the site, this limited my choices even more. Most cloud supplier like AWS, Google cloud and Azure, however offers node app support but they are rather expensive.

In the end I opted for Azure as I am more familiar with this infrastructure and they offer a great feature, once the App Service to run you app in is created, you can set-up a local git repository in the service. This means I can push my code directly from my local machine to the server by simply setting a new remote for my local repository

$ git remote add azure https://@localgitdeployment.scm.azurewebsites.net:443/localgitdeployment.git

Azure also has a nice feature that senses that my app is a node app and it will handle all the npm installs for me

Pin It on Pinterest

Share This

Share This

Share this post with your friends!