This is a assignment of a simple shopping cart functionality for an e-commerce website.
This project uses the MEAN stack:
- Mongoose.js (MongoDB): Database
- Express.js: Backend framework
- Angular: Frontend framework
- Node.js: Runtime environment
Other tools and technologies used:
- Angular CLI: Frontend scaffolding
- Bootstrap: Layout and styles
- Font Awesome: Icons
- JSON Web Token: User authentication
- Angular JWT: JWT helper for Angular
- Bcrypt.js: password encryption
- Install Node.js(14.9.0) and MongoDB
- Install Angular CLI(11.0.3):
npm i -g @angular/cli
- From project root folder install all the dependencies:
npm i
npm run dev
: concurrently execute MongoDB, Angular build, TypeScript compiler and Express server.
A window will automatically open at localhost:4200. Angular and Express files are being watched. Any change automatically creates a new bundle, restart Express server and reload your browser.
npm run prod
: run the project with a production bundle and AOT compilation listening at localhost:3000
docker-compose up
- Go to localhost:3000
npm run seed
: for seeding data
- Download and install Heroku Toolbelt
- In a terminal, run
heroku login
and enter your Heroku credentials - From your app directory run
heroku create
- Use the command
heroku config:set KEY=val
to set the different environment variables (KEY=val) for your application (i.e.heroku config:set BASE_URL=[heroku App Name].herokuapp.com
orheroku config:set MONGODB_URI=mongodb://dbuser:<password>@cluster0-shard-00-00-sdf32.mongodb.net:27017,cluster0-shard-00-01-sdf32.mongodb.net:27017/<dbname>?ssl=true&retryWrites=true&w=majority
(see Hosted MongoDB Atlas below), etc.) Make sure to set the environment variables for SENDGRID_USER, SENDGRID_PASSWORD, and any other API that you are using as well. - Lastly, do
git push heroku master
.
Please note that you may also use the Herko Dashboard to set or modify the configurations for your application.
or
- Create a EC2 Linux machine on AWS
- Edit the EC2 Security Group and add TCP port
3000
as an Inbound rule for Source0.0.0.0/0
- Clone this repo into the EC2 machine
- If you use a remote MongoDB instance, edit
.env
file - Run
npm ci
- Run
npm run build
ornpm run buildprod
- Run
npm start
- The app is now running and listening on port 3000
- You can now visit the public IP of your AWS EC2 followed by the port, eg:
12.34.56.78:3000
- Tip: use pm2 to run the app instead of
npm start
, eg:pm2 start dist/server/app.js
Run ng test
to execute the frontend unit tests via Karma.
Run npm run testbe
to execute the backend tests via Mocha (it requires mongod
already running).
Run npm run lint
to execute TS linting, HTML linting and SASS linting.
To get more help on the angular-cli
use ng --help
or go check out the Angular-CLI README.