Getting Started with Angular Full Stack

Apr 15, 2024 | Programming

Welcome to the world of Angular Full Stack! This project provides a seamless integration of Angular with a backend and database, all while using Typescript throughout the stack. In this article, we’ll guide you through the installation, setup, and running of an Angular Full Stack application.

What You Need

Before diving into the installation, ensure you have the following prerequisites:

  • Install Node.js and MongoDB
  • Install Angular CLI: npm i -g @angular/cli
  • From the project root folder, install all the dependencies: npm i

Running Your Application

You have multiple modes to run your application:

1. Development Mode

Use the following command to run your application in development mode:

npm run dev

This command will use concurrently to execute MongoDB, Angular build, TypeScript compiler, and Express server. Your application will be accessible at localhost:4200.

2. Production Mode

For production, run the following command:

npm run prod

This mode will bundle your application for production and listen on localhost:3000.

3. Manual Mode

If you prefer a manual setup:

  • Build frontend: npm run build:dev for development or npm run build for production
  • Build backend: npm run predev
  • Run MongoDB: mongod
  • Run the app: npm start

4. Docker Setup

To run your application using Docker, use:

sudo docker-compose up

Your application will be available at localhost:3000.

5. Deploying on AWS EC2

For deploying on an AWS EC2 instance, follow these steps:

  1. Create an EC2 Linux machine on AWS.
  2. Edit the EC2 Security Group to add TCP port 3000 as an inbound rule.
  3. Clone this repository into the EC2 machine.
  4. If using a remote MongoDB instance, edit the .env file.
  5. Run npm ci.
  6. Run npm run build.
  7. Run npm start.
  8. Your application is now running and listening on port 3000.

Understanding the Code Structure

Imagine building a house: the frontend is your beautiful interior design, while the backend and database form the foundation and structure. Each part needs to work together comprehensively to create a functional living space. In the Angular Full Stack project, this analogy holds true:

  • Frontend (Angular 2+): This is the visual aspect of your app, like painting the walls and arranging furniture to create a welcoming environment for users.
  • Backend (Express.js): This acts as the infrastructure, handling requests and responses—similar to how a house’s plumbing moves water in and out.
  • Database (MongoDB with Mongoose.js): This is like the storeroom of your house, storing data securely for later use.

Troubleshooting Tips

If you encounter any issues, consider the following troubleshooting ideas:

  • Make sure Node.js and MongoDB are properly installed.
  • Verify that your commands are being typed correctly and you’re in the correct project directory.
  • Check the logs for any error messages that can provide more context.
  • Consult the official wiki for more detailed instructions and help. For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Running Tests and Linters

To ensure the functionality and quality of your application, you can run tests:

  • Frontend unit tests: ng test via Karma.
  • Backend tests: npm run test:be via Jest (requires MongoDB to be running).

Run linters with: npm run lint for code quality checks.

Conclusion

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Happy coding!

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox