Node Land
#CRUD in Node.js Land
“Now that I know what Node.js can do, I feel like I was living in a stone age of some sorts.”
My recent internship at Axelerant, where I worked with their front-end architect Bassam Ismail, (along with a friend, who is also co-authoring this post, and was interning there as well) taught me a lot that I didn’t know before. I knew JavaScript was turning things around and making PHP look like a smelly cat but not like this.
Node.js
“There’s nothing else involved there but JavaScript to create an environment to run real-time web applications.”
I am not an expert on Node.js but I know a fair amount about the platform. Node.js is an environment for server-side and networking applications, written in only JavaScript. And that’s the most wonderful part! There’s nothing else involved there but JavaScript to create an environment to run real-time web applications. It works across all major platforms like OS X, Microsoft Windows, Linux, etc and provides an API which we can use to build web applications with much less effort as compared to what PHP has to offer. Installing node is very easy. You can check the Node.js API to find out more and so much more about it.
sudo apt-get install nodejs
Including (or requiring) a module in Node is very easy. You just require the app in your app.js file where most of your logic is written and then use the functions from that module right in that file. Here’s an example of how to require modules in Node:
var express = require('express');
// imports the express module
In the above example we have required the express framework that includes the express module in our project. We built the app on top of Node using the Express web framework for making web applications.
NPM
NPM stands for Node Package Manager and that’s what you use to install packages and modules that are written in JavaScript and for Node.js. It’s like bower but it works with Node. It automatically updates each package that you have installed and updates the package.json file with the versions of the installed packages. This tool is indispensable to anyone who uses Node.
Installing packages using NPM was as simple as
npm install package-name
This will install the package in your current folder or you could use -g to install it globally.
npm install package-name -g
During the internship we used Node.js to create a full, working CRUD app and called the project Janus Blog (which we turned into a blogging app). Instead of using SASS, we used Stylus to style the front-end and the experience while writing code with Stylus was so much better and convenient than SASS. I am not talking about the negative effect of convenience where you get lazy and let the software do everything for you. What Stylus did was that it automatically made us write clean and better managed code. You cannot get that from SASS. That’s the power of Stylus. The Python-like indentation seemed uncomfortable to me at first but after a while I started enjoying writing with it.
Tools and Services
All the development work was done on Mac and Ubuntu machines and hosted on GitHub. We used the following tools while working with Node.js :
- Node.js: Check their API at Node’s website
- ExpressJS: web applications framework
- NPM: To install and manage the following packages.
- Express
- Jade
- Mongoose
- Morgan
- basicAuth
You can check the list of packages used in the package.json file on my GitHub.
I can’t explain each and every tool and module that we used for the sake of this post. You can google all of them and find amazing documentation explaining everything.
The code base for the app we created is available here on Github and can be used straight from there without any changes unless you want to fork and improve the app.
This post was co-authored by Abdul Majid