Home Logic Ubuntu (Linux) Blog

BocaJS: NodeJS + Postgres

Server Software: ExpressJS

We are going to use ExpressJS on the server page (server.js).

NPM Install: ExpressJS

$ npm install express

Why ExpressJS?

  1. Marketability: Organizations using NodeJS tend to use ExpressJS. When applying to a job, that's going to be a bullet point with HR.
  2. Quick Setup: I came to NodeJS from a LAMP stack background. Many NodeJS newbs are not familar with writing the code for a server page. Express makes it quick and easy to set up a local NodeJS environment.
  3. Quality: Because many of us are new to server pages, our server code may not be the best. Programming takes practice. Express has already provided good code that is highly supported.
  4. Compatibility: Most modules you will want to install are made to work with ExpressJS. It should not cause conflicts with other major libraries. We should follow suit with our code and make sure our vanilla NodeJS is also compatible with ExpressJS.

The server page we will make today is intended for a development environment. There are extra steps you would take prior to putting your app live.

BocaJS host, Damian Montero is the man to see about NodeJS server pages and cloud hosting. He presented on this at a recent BocaJS meetup. Check out Damian's GitHub for examples.

Check out the ExpressJS documentation: npm express

NPM Install: Multer (Express)

$ npm install --save multer

I used this for the image uploader. An image uploader is important for a CMS to have, but we can not write everything from scratch in one presentation. We are just using it for the image Uploader (an isolated feature on its own page).

Why Multer?

I just looked for something quick and easy to include this important feature. The code is essential copy/pasted from their documantation: github: multer

$ npm install --save multer

Since the code is clearly explained in their documentation, I will just give you the image uploader code to copy/paste.

  imageUploader.js

************************
   javascript
   imageUploader.js
*************************

NPM Install: body-parser

$ npm install body-parser

Note: depending on which version of NodeJS/ExpressJS you use, you may or may not need body-parser. My tutorials teach people how to set up Ubuntu programming environments and I know install/setup can get draining. I try to write my tutorials with code that will work out of the box on Ubuntu. There will be future tutorials on updates.