The MEAN stack allows you to build complete applications using one programming language: JavaScript. In this tutorial, we built upon the first part (Creating an Angular app) which built the front-end, and this part builds the backend with a RESTful API and Database.

REST API with Node.js

We are going to use express generator and create a folder called server.

First install the generator packages:

1
npm i -g express-generator

Note: You should have Node and NPM/Yarn installed.

REST API using ExpressJS

Now let’s scaffold the app using the generator:

1
express server -e

Let’s install all its dependencies on the server folder:

1
cd server && npm i

and now let’s make sure it’s working:

1
npm start

Go to localhost on port 3000 and make sure you can see a “Welcome to Express”

http://localhost:3000/

Changes: a3fcacd - REST API using ExpressJS: scaffold

Creating a host alias for the server

We want to run the server to work regarless of the enviroment where we run it. (It will be useful for Docker later on)

For that we can create an alias by editing the hosts:

  • Windows: c:\windows\system32\drivers\etc\hosts
  • Linux/Mac: /etc/hosts

Once you can open the file, you drop the following line at the end:

#docker #mean stack #node #angular #typescript #mongodb

Modern MEAN Stack Tutorial with Docker (Angular, Node, Typescript and Mongodb)
2.70 GEEK