2017-05-26 15:28:06 -04:00
# Setup for local development
2017-03-27 11:08:53 -04:00
2017-02-22 13:09:39 -05:00
{@a develop-locally}
2017-03-31 19:57:13 -04:00
2017-02-22 13:09:39 -05:00
The < live-example name = quickstart > QuickStart live-coding</ live-example > example is an Angular _playground_ .
2017-06-09 17:48:53 -04:00
It's not where you'd develop a real application.
2017-03-11 10:36:40 -05:00
You [should develop locally ](guide/setup#why-locally "Why develop locally" ) on your own machine ... and that's also how we think you should learn Angular.
2017-02-22 13:09:39 -05:00
Setting up a new project on your machine is quick and easy with the **QuickStart seed** ,
2017-06-09 17:48:53 -04:00
maintained [on github ](https://github.com/angular/quickstart "Install the github QuickStart repo" ).
2017-03-31 19:57:13 -04:00
2018-04-26 18:47:31 -04:00
Make sure you have [Node.js® and npm installed ](guide/setup#install-prerequisites "What if you don't have Node.js and npm?" ).
2017-05-04 12:46:43 -04:00
2017-02-22 13:09:39 -05:00
{@a clone}
2017-03-31 19:57:13 -04:00
2017-05-26 15:28:06 -04:00
## Clone
2017-02-22 13:09:39 -05:00
Perform the _clone-to-launch_ steps with these terminal commands.
2017-03-30 15:04:18 -04:00
2017-02-22 13:09:39 -05:00
< code-example language = "sh" class = "code-shell" >
2017-03-31 19:57:13 -04:00
git clone https://github.com/angular/quickstart.git quickstart
cd quickstart
npm install
npm start
2017-02-22 13:09:39 -05:00
< / code-example >
2017-04-10 11:51:13 -04:00
< div class = "alert is-important" >
2017-02-22 13:09:39 -05:00
2017-03-31 19:57:13 -04:00
2017-06-20 14:53:17 -04:00
`npm start` fails in _Bash for Windows_ in versions earlier than the Creator's Update (April 2017).
2017-02-22 13:09:39 -05:00
2017-04-10 11:51:13 -04:00
< / div >
2017-02-22 13:09:39 -05:00
{@a download}
2017-03-31 19:57:13 -04:00
2017-05-26 15:28:06 -04:00
## Download
2017-03-31 07:23:16 -04:00
< a href = "https://github.com/angular/quickstart/archive/master.zip" title = "Download the QuickStart seed repository" > Download the QuickStart seed< / a >
2017-02-22 13:09:39 -05:00
and unzip it into your project folder. Then perform the remaining steps with these terminal commands.
2017-03-30 15:04:18 -04:00
2017-02-22 13:09:39 -05:00
< code-example language = "sh" class = "code-shell" >
2017-03-31 19:57:13 -04:00
cd quickstart
npm install
npm start
2017-02-22 13:09:39 -05:00
< / code-example >
2017-04-10 11:51:13 -04:00
< div class = "alert is-important" >
2017-02-22 13:09:39 -05:00
2017-03-31 19:57:13 -04:00
2017-06-20 14:53:17 -04:00
`npm start` fails in _Bash for Windows_ in versions earlier than the Creator's Update (April 2017).
2017-02-22 13:09:39 -05:00
2017-04-10 11:51:13 -04:00
< / div >
2017-02-22 13:09:39 -05:00
{@a non-essential}
2017-03-31 19:57:13 -04:00
2017-02-22 13:09:39 -05:00
## Delete _non-essential_ files (optional)
You can quickly delete the _non-essential_ files that concern testing and QuickStart repository maintenance
(***including all git-related artifacts*** such as the `.git` folder and `.gitignore` !).
2017-04-10 11:51:13 -04:00
< div class = "alert is-important" >
2017-02-22 13:09:39 -05:00
2017-03-31 19:57:13 -04:00
2017-02-22 13:09:39 -05:00
Do this only in the beginning to avoid accidentally deleting your own tests and git setup!
2017-04-10 11:51:13 -04:00
< / div >
2017-02-22 13:09:39 -05:00
2017-03-31 19:57:13 -04:00
2017-02-22 13:09:39 -05:00
Open a terminal window in the project folder and enter the following commands for your environment:
### OS/X (bash)
2017-03-30 15:04:18 -04:00
2017-02-22 13:09:39 -05:00
< code-example language = "sh" class = "code-shell" >
2017-03-31 19:57:13 -04:00
xargs rm -rf < non-essential-files.osx.txt
rm src/app/*.spec*.ts
rm non-essential-files.osx.txt
2017-02-22 13:09:39 -05:00
< / code-example >
2017-03-31 19:57:13 -04:00
2017-02-22 13:09:39 -05:00
### Windows
2017-03-30 15:04:18 -04:00
2017-02-22 13:09:39 -05:00
< code-example language = "sh" class = "code-shell" >
2017-03-31 19:57:13 -04:00
for /f %i in (non-essential-files.txt) do del %i /F /S /Q
rd .git /s /q
rd e2e /s /q
2017-02-22 13:09:39 -05:00
< / code-example >
{@a seed}
2017-03-31 19:57:13 -04:00
2017-02-22 13:09:39 -05:00
## What's in the QuickStart seed?
2017-03-27 11:08:53 -04:00
2017-03-31 19:57:13 -04:00
2017-03-27 11:08:53 -04:00
The **QuickStart seed** contains the same application as the QuickStart playground.
But its true purpose is to provide a solid foundation for _local_ development.
2017-06-09 17:48:53 -04:00
Consequently, there are _many more files_ in the project folder on your machine,
2017-03-31 19:57:13 -04:00
most of which you can [learn about later ](guide/setup-systemjs-anatomy "Setup Anatomy" ).
2017-03-27 11:08:53 -04:00
{@a app-files}
2017-03-31 19:57:13 -04:00
2017-03-27 11:08:53 -04:00
Focus on the following three TypeScript (`.ts`) files in the ** `/src` ** folder.
2017-03-30 15:04:18 -04:00
2017-04-11 16:44:52 -04:00
< div class = 'filetree' >
2017-03-27 11:08:53 -04:00
2017-04-11 16:44:52 -04:00
< div class = 'file' >
2017-03-27 11:08:53 -04:00
src
2017-04-11 16:44:52 -04:00
< / div >
< div class = 'children' >
< div class = 'file' >
2017-03-27 11:08:53 -04:00
app
2017-04-11 16:44:52 -04:00
< / div >
< div class = 'children' >
< div class = 'file' >
2017-03-27 11:08:53 -04:00
app.component.ts
2017-04-11 16:44:52 -04:00
< / div >
2017-03-27 11:08:53 -04:00
2017-04-11 16:44:52 -04:00
< div class = 'file' >
2017-03-27 11:08:53 -04:00
app.module.ts
2017-04-11 16:44:52 -04:00
< / div >
2017-03-27 11:08:53 -04:00
2017-04-11 16:44:52 -04:00
< / div >
2017-03-27 11:08:53 -04:00
2017-04-11 16:44:52 -04:00
< div class = 'file' >
2017-03-27 11:08:53 -04:00
main.ts
2017-04-11 16:44:52 -04:00
< / div >
2017-03-27 11:08:53 -04:00
2017-04-11 16:44:52 -04:00
< / div >
2017-03-27 11:08:53 -04:00
2017-04-11 16:44:52 -04:00
< / div >
2017-03-27 11:08:53 -04:00
< code-tabs >
< code-pane title = "src/app/app.component.ts" path = "setup/src/app/app.component.ts" >
< / code-pane >
< code-pane title = "src/app/app.module.ts" path = "setup/src/app/app.module.ts" >
< / code-pane >
< code-pane title = "src/main.ts" path = "setup/src/main.ts" >
< / code-pane >
< / code-tabs >
2017-03-31 19:57:13 -04:00
2017-06-09 17:48:53 -04:00
All guides and cookbooks have _at least these core files_ .
2017-02-22 13:09:39 -05:00
Each file has a distinct purpose and evolves independently as the application grows.
Files outside `src/` concern building, deploying, and testing your app.
They include configuration files and external dependencies.
Files inside `src/` "belong" to your app.
Add new Typescript, HTML and CSS files inside the `src/` directory, most of them inside `src/app` ,
unless told to do otherwise.
The following are all in `src/`
2017-03-30 15:04:18 -04:00
2017-02-22 13:09:39 -05:00
< style >
td, th {vertical-align: top}
< / style >
2017-03-30 15:04:18 -04:00
2017-02-22 13:09:39 -05:00
< table width = "100%" >
< col width = "20%" >
< / col >
< col width = "80%" >
< / col >
< tr >
< th >
File
< / th >
< th >
Purpose
< / th >
< / tr >
< tr >
< td >
2017-03-31 07:23:16 -04:00
< code > app/app.component.ts< / code >
2017-02-22 13:09:39 -05:00
< / td >
< td >
2017-03-31 19:57:13 -04:00
Defines the same `AppComponent` as the one in the QuickStart playground.
It is the **root** component of what will become a tree of nested components
2017-06-09 17:48:53 -04:00
as the application evolves.
2017-02-22 13:09:39 -05:00
< / td >
< / tr >
2017-03-31 07:23:16 -04:00
< tr >
2017-03-30 15:04:18 -04:00
2017-02-22 13:09:39 -05:00
< td >
< code > app/app.module.ts< / code >
< / td >
< td >
2017-03-31 19:57:13 -04:00
2017-06-09 17:48:53 -04:00
Defines `AppModule` , the [root module ](guide/bootstrapping "AppModule: the root module" ) that tells Angular how to assemble the application.
2017-03-31 19:57:13 -04:00
Right now it declares only the `AppComponent` .
Soon there will be more components to declare.
2017-02-22 13:09:39 -05:00
< / td >
< / tr >
< tr >
< td >
2017-03-31 07:23:16 -04:00
< code > main.ts< / code >
2017-02-22 13:09:39 -05:00
< / td >
< td >
2017-03-31 19:57:13 -04:00
2017-04-30 16:10:32 -04:00
Compiles the application with the [JIT compiler ](guide/glossary#jit ) and
2017-07-04 10:58:20 -04:00
[bootstraps ](guide/bootstrapping )
2017-03-31 19:57:13 -04:00
the application's main module (`AppModule`) to run in the browser.
The JIT compiler is a reasonable choice during the development of most projects and
2017-11-03 13:08:28 -04:00
it's the only viable choice for a sample running in a _live-coding_ environment like Stackblitz.
2017-03-31 19:57:13 -04:00
You'll learn about alternative compiling and [deployment ](guide/deployment ) options later in the documentation.
2017-02-22 13:09:39 -05:00
< / td >
< / tr >
< / table >
2017-03-27 11:08:53 -04:00
2018-07-19 18:00:08 -04:00
< div class = "alert is-helpful" >
2017-03-27 11:08:53 -04:00
2017-03-31 19:57:13 -04:00
2017-02-22 13:09:39 -05:00
### Next Step
2017-04-30 16:10:32 -04:00
If you're new to Angular, we recommend you follow the [tutorial ](tutorial "Tour of Heroes tutorial" ).
2017-03-27 11:08:53 -04:00
2017-04-10 11:51:13 -04:00
< / div >
2017-03-27 11:08:53 -04:00
2017-02-22 13:09:39 -05:00
< br > < / br > < br > < / br >
{@a install-prerequisites}
2017-03-31 19:57:13 -04:00
2018-04-26 19:38:23 -04:00
## Appendix: Node.js and npm
2017-03-31 19:57:13 -04:00
2018-04-26 18:47:31 -04:00
[Node.js ](https://nodejs.org/en/ ) and the [npm ](https://www.npmjs.com/ ) package manager are essential to modern web development with Angular and other platforms.
2018-04-26 22:50:42 -04:00
Node.js powers client development and build tools.
The _npm_ package manager, which is itself a _Node.js_ application, installs JavaScript libraries.
2017-03-27 11:08:53 -04:00
< a href = "https://docs.npmjs.com/getting-started/installing-node" target = "_blank" title = "Installing Node.js and updating npm" >
Get them now< / a > if they're not already installed on your machine.
2018-04-26 18:47:31 -04:00
**Verify that you are running Node.js `v8.x` or higher and npm `5.x` or higher**
2017-03-27 11:08:53 -04:00
by running the commands `node -v` and `npm -v` in a terminal/console window.
Older versions produce errors.
2018-04-26 18:47:31 -04:00
We recommend [nvm ](https://github.com/creationix/nvm ) for managing multiple versions of Node.js and npm.
You may need [nvm ](https://github.com/creationix/nvm ) if you already have projects running on your machine that use other versions of Node.js and npm.
2017-03-31 07:23:16 -04:00
{@a why-locally}
2017-03-31 19:57:13 -04:00
2017-03-31 07:23:16 -04:00
## Appendix: Why develop locally
2017-11-03 13:08:28 -04:00
< live-example title = "QuickStart Seed in Stackblitz" > Live coding< / live-example > in the browser is a great way to explore Angular.
2017-03-31 07:23:16 -04:00
Links on almost every documentation page open completed samples in the browser.
You can play with the sample code, share your changes with friends, and download and run the code on your own machine.
2017-04-30 16:10:32 -04:00
The [QuickStart ](guide/quickstart "Angular QuickStart Playground" ) shows just the `AppComponent` file.
2017-03-31 07:23:16 -04:00
It creates the equivalent of `app.module.ts` and `main.ts` internally _for the playground only_ .
so the reader can discover Angular without distraction.
2017-06-09 17:48:53 -04:00
The other samples are based on the QuickStart seed.
2017-03-31 07:23:16 -04:00
As much fun as this is ...
2017-03-31 19:57:13 -04:00
2017-11-03 13:08:28 -04:00
* you can't ship your app in Stackblitz
2017-03-31 07:23:16 -04:00
* you aren't always online when writing code
* transpiling TypeScript in the browser is slow
* the type support, refactoring, and code completion only work in your local IDE
2017-11-03 13:08:28 -04:00
Use the < live-example title = "QuickStart Seed in Stackblitz" > live coding</ live-example > environment as a _playground_ ,
2017-03-31 07:23:16 -04:00
a place to try the documentation samples and experiment on your own.
It's the perfect place to reproduce a bug when you want to
2017-04-21 13:10:19 -04:00
< a href = "https://github.com/angular/angular/issues/new" title = "File a documentation issue" > file a documentation issue< / a > or
< a href = "https://github.com/angular/angular/issues/new" title = "File an Angular issue" > file an issue with Angular itself< / a > .
2017-03-31 07:23:16 -04:00
2017-04-21 10:17:03 -04:00
For real development, we strongly recommend [developing locally ](guide/setup#develop-locally ).
2018-01-26 23:45:03 -05:00
## Appendix: develop locally with IE
If you develop angular locally with `ng serve` , there will be `websocket` connection being setup automatically between browser and local dev server, so when your code change, browser can automatically refresh.
In windows, by default one application can only have 6 websocket connections, < a href = "https://msdn.microsoft.com/library/ee330736%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396#websocket_maxconn" title = "MSDN WebSocket settings" > MSDN WebSocket Settings< / a > .
So if IE was refreshed manunally or automatically by `ng serve` , sometimes, the websocket will not close properly, when websocket connections exceed limitations, `SecurityError` will be thrown, this error will not affect the angular application, you can just restart IE to clear this error, or modify the windows registry to update the limitations.