Mean Stack App Sample — The backend (I)

Pablo Ezequiel
Feb 23, 2017 · 4 min read

Let´s start some test over the repo:

Running the sample

$ git clone https://github.com/DavideViolante/Angular2-Full-Stack.git

$ mongod — dbpath /usr/local/var/data/db/

Compile with

The backend is the server

$ npm install

and run with the server side with

$ npm run be

the same that:

$ nodemon src/server/app.js

Let´s test the server side: the cat´s database is empty

in deed, it is empty

Let´s insert two cats “Felix” and “Garfiel” to the database

and we can recover it from the API REST:

Let´s recover all cats:

http://localhost:3000/cats

http://localhost:3000/cat/58ae225ed2f8d65bce07f946

Standalone Server App

Let´s run an Standalone server App just for the backend:

$ npm init

Next, I will add basic dependences:

$ npm install express

$ npm install body-parser

$ npm install mongoose

The — save and — save-dev install flags also add entry to package.json

$ npm install <package_name> --saveexample $ npm install mongoose --save 
$ npm install express --save
$ npm install body-parser --save --save-dev
$ npm install morgan --save --save-dev

note: “morgan” a log lib it is not necessary for the sample

Ok, we have installed the most basic libraries for the backend, all of three are in the node_mongo dir with their dependences. We can observe two thins: the installation is local to the project, and If we run the command again, npm don´t bring only the dependences that are missing.

we can see that we

Let´s run again but with the — save and — save-dev options

And we can see also how the package.json is modified

Let´s edit a simple app.js (Copy&Paste from the server full stack proyect)

And server standalone is running

A little comment about nodemon

nodemon monitors for any changes in our node.js application and automatically restart the server, so, it is common to use nodemon instead node:

Let’s install it:

Let´s run it

Reload:

Ok! we could see how the api is reloaded when the node js file is modified

Can I combine the API with swagger or with Looback?

I will explore it later, but I have found a very good post on https://blog.risingstack.com/swagger-nodejs/ that also talk about swagger with docker

Also I remember that I went to a tech event where they suggested to explore Strongloop with Loopback

This is a good post about Looback

https://strongloop.com/strongblog/compare-express-restify-hapi-loopback/

In my personal and humble opinion, Loopback looks easier than swagger to integrate to node.js projects, so I will make just a test only with it

Loopback with Node.JS

That´s will be a next post, but by the way I will stop the post there….

Pablo Ezequiel

Written by

Dev and Tech. Sharing while I am learning (#cloud, #mobile)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade