My M.E.A.N. website server/back-end (Alpha)
This is the server side. Client side is available HERE
Informations
My MEAN website is a MEAN's web application that I'm creating as a personal website, but also for other users. It's composed by:
- M: a MongoDb's database
- E: a back-end with Express js
- A: a front-end in Angular >= 4
- N: a back-end in Node.js
- redis
- webpack
- and other stuff
A possible extension of this project will be a configurable template to build a custom web app very quickly. This is my final goal, please be patient :)
Attention! This project is still an alpha, so it's not production ready. Please be careful. If you are interested, star this project on GitHub, share it and create pull requests.
Testing:
- back-end unit: almost done (only the necessary things)*. coverage >=90%
- back-end integration: almost done*. coverage >=90%
(*) I unit-tested only public functions and I tested all APIs (integration) except for OAUTH2/PassportJS. This is because, it's extremely difficult to test passportjs (for 3dparty services, not for the local auth) without to use browsers (like Zombie or Phantom). In my opinion an integration-test for a back-end api must use only backend's code, not also a browser (browser is on client and not on server :) ). The problem is that to test PassportJS without a browser it's really difficult. I asked on StackOverflow HERE, without receive any answers. For this reason, I decided to unit-tests these APIs (not APIs theirself but their functions/logics). If you want to help me to write integration-test's case for PassportJS, check this file
Requirements
- macOS, Linux or Windows 10 with admin privileges
- Node.js + npm
- MongoDB and redis
- some global npm dependencies
- work in progress... (this is only an alpha, please be patient)
News
- 10/06/2017 - My MEAN website Alpha 9 public release HERE
- 08/20/2017 - My MEAN website Alpha 8 public release HERE
- 08/10/2017 - My MEAN website Alpha 7 public release HERE
- 04/09/2017 - My MEAN website Alpha 6 public release HERE
- 01/21/2017 - My MEAN website Alpha 5 public release HERE
- 12/30/2016 - My MEAN website Alpha 4 public release HERE
- 11/28/2016 - My MEAN website Alpha 3 public release HERE
- 10/27/2016 - My MEAN website Alpha 2 public release HERE
- 08/15/2016 - My MEAN website Alpha 1 public release HERE
How to install (MacOS)
- from the
setup
folder of this project, runbash install-macos.sh
- import the db dump (.bson) from
db-dump-prod
's folder either runningdb-dump-prod/init.sh
to do it automatically thanks to bothmongo
admongorestore
CLIs, or using Studio 3T (previously MongoChef)
How to install (Linux)
Tested only on Ubuntu
- from the
setup
folder of this project, runbash install-ubuntu.sh
- import the db dump (.bson) from
db-dump-prod
's folder either runningdb-dump-prod/init.sh
to do it automatically thanks to bothmongo
admongorestore
CLIs, or using Studio 3T (previously MongoChef)
How to install (Windows)
Tested only on Windows 10
- install both Mozilla Firefox and Google Chrome
- install Node.js from the official website
- install MongoDb Community from the official website
- create a db called
KS
(obviously you have to start MongoDb to do that). You can configure this value later, but for debug/local environment I suggest this name - import the db dump (.bson) from
db-dump-prod
's folder either runningdb-dump-prod/init.sh
to do it automatically thanks to bothmongo
admongorestore
CLIs (if available in your PATH variable), or using Studio 3T (previously MongoChef) - install redis-server for Windows (file .msi) HERE
- install Python 2.7.x from the official website
- from the
setup
folder of this project, run with PowerShell as administatorbash install-windows.sh
If you'll have problems with node-zopfli
, you have to install it properly following this tutorial. There are two options, try with the first one npm install --global --production windows-build-tools
, if it will fail, use option 2.
Both options will require to download really big files from microsoft.com (manually or automatically). So, be careful.
How to setup
- You have to rename
.env_example
's file into.env
(debug/local config - mandatory) and create another copy called.env_prod
(production config)
1a. ConfigureFRONT_END_PATH
with the relative position of the main folder of THE CLIENT SIDE OF THIS PROJECT. For.env_prod
you should use simplypublic
1b. ConfigureREDIS_HOST
,REDIS_PORT
andREDIS_TTL
. If you are in a debug/local environment you should use the example values
1c. Configure bothMONGODB_URI
andMONGODB_TESTING_URI
with your db path. I suggest to use the example value without user/password and with a db calledKS
1d. replaceYOU KEY/ID
with the keys obtained from facebook/github... oauth applications.
1e. replaceYOUR_EMAIL
andYOUR_PASSWORD
with the data of your e-mail account
1f. replaceYOUR GOOGLE RECAPTCHA...
with Google Recaptcha2's keys
1g. reaplaceINSERT A JWT SECRET HERE
with an alphanumerical string (I'm using a random string with a length = 72) - execute this command
npm install
into the root folder (if it will fail, run it again :)) - start redis-server (both on Linux and Mac run
redis-server
, on Windows startC:\Program files\Redis\redis-server.exe
) - start MongoDb (on Linux run
mongod
, on Mac runsudo mongod
and on Windows startC:\Program Files\MongoDB\Server\<your version here>\bin\mongod.exe
) - execute this command
npm start
into the root folder to start this application (back-end)
How to run both unit and integration tests (server-side)
npm test
How to start (development mode)
- cd 'main folder of this project'
npm start
- all REST webservices will be available at http://localhost:3000 for instance try with http://localhost:3000/api/projects
How to start (production mode)
I decided to use pm2 (with pm2.json config file) to run in cluster mode (max
processes) this project in a production environment
- cd 'main folder of this project'
npm run prod:start
- all REST webservices will be available at http://localhost:3000 for instance try with http://localhost:3000/api/projects
- if you want to stop it use
npm run prod:stop
Features
Work in progress... (this is only an alpha, please be patient)
Future extensions
Work in progress... (this is only an alpha, please be patient)
Images
Note: updated local profile info
Note: multiple account connected (Facebook and Github)
Configuration
From Alpha 5 I created many entries in .env, so you could start to configure this application. Work in progress... (this is only an alpha, please be patient)
Thanks
A special thanks to the authors of this book, because very useful to understand how to develop a modern web application: BOOK1
License
Copyright 2015-2017 Stefano Cappa
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
**Created by Stefano Cappa**