Skip to content

Instantly share code, notes, and snippets.

@brandonjyee
Last active May 22, 2020 15:19
Show Gist options
  • Save brandonjyee/ef831cc90de74be616cfda67d99613eb to your computer and use it in GitHub Desktop.
Save brandonjyee/ef831cc90de74be616cfda67d99613eb to your computer and use it in GitHub Desktop.
[Angular] Quick & Dirty cheatsheet
The following are common command-line commands for using Angular. Assumes you have node.js already installed, which is a prerequisite.
npm i npm # Update to the latest version of node package manager (npm). May be necessary to have latest version so in order to d/l some packages.
# npm is basically a super popular software registry that has hundreds of thousands of packages you can install via npm commands. Angular and ReactJS rely on it to install their modules.
npm install -g @angular/cli # use to install the angular Command-Line Interface (CLI). Any commands that start with "ng" are using the CLI.
ng new my-app # Create a new app called "my-app". Creating a new app takes me ~10+ mins on my laptop b/c it generates ~300MB of files, so feel free to grab a cup of coffee in the meantime.
cd my-app # Go to the new app’s directory to serve it
ng serve --open # Command to serve the app locally at http://localhost:4200 . This is using javascript web-dev-server. It'll refresh the page whenever you make changes to any files in the app. Very useful!
ng build # Build the app. Generates a "dist" folder in the app. Take what’s in the dist folder and put it on your web server to deploy it
ng build --base-href=/my/app/ # Do this if you’re deploying to a subfolder to get the base path right. This example assumes you're hosting it at "http://yoursite.com/my/app"
ng build --prod # Build for production. Optimized
ng build --prod --build-optimizer # Can further optimize
ng generate component hero-detail # Create a component called "hero-detail"
ng g component hero-detail # Can just use "g" instead of "generate" as a shorthand if you're lazy
ng generate service hero # Generate a service called "hero"
ng generate service hero --module=app # Provide the service to the dependency injection system
ng generate module app-routing --flat --module=app # Create the routing module
npm install angular-in-memory-web-api --save # Install the In-Memory manager. Helps w/ local deployment
npm install # Do this in the directory of a project when you d/l a new project from github or somewhere else. It'll likely not have the
# node_modules folder (b/c that folder is typically huge (~300MB)). So you’ll need to generate it in order to run the app.
# Keep in mind this can take a while. On my laptop, it takes ~10+ mins.
# You can also copy an existing node_modules folder over, but that’s not recommended.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment