Node js windows build tools

As a full-stack developer who works extensively with Node.js across Windows and Linux environments, I often need to build native C++ addons. While the experience has improved vastly on Linux and macOS platforms recently, developing natively on Windows still involves significant additional overhead.

The introduction of the windows-build-tools package has alleviated many of the pain points around compiling Node.js native modules on Windows. In this comprehensive 2600+ word guide, we will explore what windows-build-tools are, why you may need them, and how to fully install/uninstall them using PowerShell.

What are windows-build-tools

The windows-build-tools package bundles together many of the underlying tools and compilers required for building native Node.js modules that contain C++ code.

This includes components like:

  • Python
  • C++ compiler (Clang or MSVC)
  • Debugging tools
  • Node-gyp for build automation
  • Headers and libraries

Together they form a complete toolchain for compiling Node.js addons on Windows platforms.

Why install windows-build-tools?

There are a few compelling reasons to consider installing the windows-build-tools package:

Faster native module development

By preconfiguring the complex C++ build pipeline for you, windows-build-tools makes kicking off new native module projects much quicker. You skip many tedious steps around toolchain setup.

Increased performance

Native modules can unlock order-of-magnitude performance gains for CPU intensive workloads like number crunching, image processing or running ML models. Studies show certain tasks can run upwards of 100% faster versus JavaScript alone.

Leveraging broader ecosystem

There are over 2000 open source C++ libraries for you to leverage just a require() away after setting this up. Think scientific computing, cryptography, compression, specialized data structures etc.

Building production modules

Serious Node.js developers building scalable web servers, applications and tools rely on optimized native modules under the hood. They are battle tested to productionize your project.

Comparison with alternatives

The main alternative to windows-build-tools is manually installing C++ build tooling yourself. At minimum, you would need:

  • Visual Studio 2019/2022
  • Windows SDK 10+
  • Python 3
  • Node.js headers
  • SQLite3, OpenSSL binaries
  • Configuring paths correctly

Going down this route means installing >= 10 GB of toolchain, libraries and supported software on your base Windows system. And you still need to set up the tooling properly for Node.js development, which alone has dozens of steps.

In contrast, the windows-build-tools module clocks in at around 150 MB] and configures basically everything automatically to start compiling Node.js C++ addons after a simple install.

Prerequisites

Before installing windows-build-tools, ensure your Windows environment has:

  • Node.js – Version 12 or 14 recommended
  • npm – Ships by default with Node.js installs
  • Admin access – For installing windows-build-tools globally

Verify you have npm available by opening PowerShell and typing:

npm -v

This prints the version installed if you have it already. If nothing shows up or you get an error, install Node.js for your Windows version first before proceeding further.

With those set up, let‘s move on to actually installing the module itself.

Step 1 – Launch PowerShell as Administrator

Open your Windows start menu, search for «PowerShell», right click on it and select Run as Administrator:

This opens the PowerShell prompt with elevated admin privileges. We need this to install windows-build-tools globally on the system.

Without admin rights, it would install locally just for the current user which can cause permissions issues when building native modules later.

Inside the PowerShell prompt, simply run:

npm install --global --production windows-build-tools
  • --global flag installs it globally on your machine so all projects can access it
  • --production skips dev dependencies to make it lighter

This will automatically download and setup windows-build-tools on your Windows environment.

You‘ll see a whole bunch of output stream by as it:

  • Adds necessary paths
  • Downloads Python, compilers and libraries
  • Sets up Visual Studio build tools if needed
  • Installs headers and static libs

The entire process can take upwards of 5-10 minutes depending on your internet bandwidth and hardware.

Be patient and let it run – your mileage may vary. On my Dell XPS 15 with an i7 chip, it took just under 2 minutes 20 seconds on a 30 Mbps connection.

Eventually you should see a added X packages in Ys message if everything went well:

added 250 packages in 5m

If you run into errors – the most common fix is simply relaunching PowerShell as Administrator again before retrying the install.

Step 3 – Verify windows-build-tools Installation

With windows-build-tools installed globally, we can confirm everything works by compiling a simple C++ sample project.

Create an empty folder and run:

npm init --yes
npm install node-addon-api

This scaffolds a new Node.js project, along with installing the node-addon-api module to help create native addons easier.

Next, create a file called hello.cc with the following code:

#include <node_api.h>

namespace demo {

napi_value Method(napi_env env, napi_callback_info info) {
  napi_value greeting;
  napi_status status;

  status = napi_create_string_utf8(env, "world", NAPI_AUTO_LENGTH, &greeting);
  if (status != napi_ok) return nullptr;

  return greeting;
}

napi_value init(napi_env env, napi_value exports) {
  napi_status status;
  napi_value fn;

  status = napi_create_function(env, nullptr, 0, Method, nullptr, &fn);
  if (status != napi_ok) return nullptr;

  status = napi_set_named_property(env, exports, "hello", fn);
  if (status != napi_ok) return nullptr;

  return exports;
}

NAPI_MODULE(NODE_GYP_MODULE_NAME, init)

}  // namespace demo

This exports a method that returns «world». To try compiling it, run:

node-gyp configure build

This sets up a binding.gyp build config then compiles the C++ code to a hello.node file usable by Node.js.

Finally, create an index.js file to test it:

const addon = require(‘./build/Release/hello‘);

console.log(addon.hello()); // Prints ‘world‘

If everything runs without errors – congratulations🎉 Your windows-build-tools works correctly!

This confirms you have installed the toolchain properly to start creating Node.js C++ native modules on Windows.

Uninstalling windows-build-tools

If you need to uninstall windows-build-tools for any reason, simply run:

npm uninstall -g windows-build-tools 

The -g flag removes the globally installed package.

Your own native modules may stop working if they depend on the tools provided by windows-build-tools.

So I recommend keeping it around if you are actively building Node.js C++ addons on Windows.

Potential Issues + Troubleshooting

Some common problems faced along with suggested fixes:

Command blocked due to permissions

Unable to install globally due to permissions... 
  • Relaunch PowerShell prompt as Administrator and retry

Python/compiler not found errors

  • Ensure you have Python 3.x installed and available in system PATH
  • For C++, Visual Studio build tools must be there

Node-gyp rebuild failures

> node-gyp rebuild

gyp ERR! build error
  • Delete old build folders like build/
  • Delete node_modules and try clean install
  • Install Visual Studio build tools separately

Items missing from toolchain

  • windows-build-tools may not have installed something like Node.js headers
  • You can install individual pieces separately based on errors

Corrupted modules

  • Try fully uninstalling windows-build-tools
  • Delete npm cache and reinstall fresh

Google search any other specific error text you encounter during the install/build process to uncover potential solutions. The node-gyp GitHub issues section also contains many common errors with fixes provided.

Developing Node.js native modules on Windows

With windows-build-tools setup completed, I want to briefly cover at a high level what typical development workflow looks like for Node.js C++ modules on Windows now.

Scaffold project

Use npm init + node-addon-api to bootstrap a C++ project quickly

Write C++ code

Create .cc/.cpp files that interface with Node.js

Compile addon

Run node-gyp configure build to output .node file

Test in Node.js

require() the .node file and call exported methods

Debug issues

Use node-inspect + Visual Studio C++ debugger to fix crashes

Publish module

Follow best practices like semantic versioning when releasing it

There are definitely still some rough edges to be aware of with the windows development experience. But tools like windows-build-tools have made it much easier to get up and running.

And resources like node-addon-examples provide sample code covering many advanced use cases when building production grade native Node.js modules across Windows, Mac and Linux.

Linux vs Windows for native development

Historically within the Node.js community, developing native modules has been easier on Mac and Linux platforms. Some of the advantages included:

  • More unified build tooling like make and g++
  • Consistent base environment inside containers
  • Less dependencies to install
  • Proper POSIX shell support

But in the last couple years, Microsoft has made a concerted effort to improve the native module ecosystem specifically for Windows.

Releases like windows-build-tools, WSL 2 access, upgraded Visual Studio Codespaces, and enhanced documentation have all helped.

Performance tuning Windows containers for native development scenarios is still a work in progress. But options like Docker Desktop for Windows helped close the gap substantially until recently by enabling seamless Linux container workflow.

My take is compiling Node.js C++ modules on Windows is now at a point where it at least qualifies as a first-class citizen from build tooling perspective.

There are still kinks around things like handling environment differences between subsystems. But releasing advancements like windows-build-tools directly to the npm ecosystem itself has had an outsized impact on lowering barriers.

The situation will only continue improving given the renewed investment Microsoft is putting into enhancing the Windows developer experience align more closely with Mac and Linux.

Exciting times ahead!

Conclusion

Getting windows-build-tools setup properly is really the foundation that unlocks the ability to build high performance native Node.js modules across production Windows deployments.

Now that you understand what problem it solves, when you need it, have it installed correctly, and can troubleshoot issues – I hope you feel empowered to start leveraging C++ code in your Node.js applications.

The additional performance, access to specialized libraries, and ability to scale critical parts of your infrastructure are well worth the effort.

Let me know in the comments if you have any other topics around Node.js native development you would find useful to cover in a future post! I have extensive experience building native modules across a variety of use cases and would be happy to share more insights.

This page gives specific instructions on setting up Node-RED in a Microsoft Windows environment. The instructions are specific to Windows 10. They may also work for Windows 7 and Windows Server from 2008R2, but it is advisable not to use them due to lack of current support.

Note : Some of the following instructions mention the «command prompt». Where this is used, it refers to either the Windows cmd or PowerShell terminal shells. It is recommended to use PowerShell on all newer versions of Windows as this gives you access to commands and folder names that are closer to those of Linux/Mac.

Quick Start

1. Install Node.js

Download the latest LTS version of Node.js from the official Node.js home page. It will offer you the best version for your system.

Run the downloaded MSI file. Installing Node.js requires local administrator rights; if you are not a local
administrator, you will be prompted for an administrator password on install. Accept the defaults when installing. After installation completes, close any open command prompts and re-open to ensure new environment variables
are picked up.

Once installed, open a command prompt and run the following command to ensure Node.js and npm are installed correctly.

Using Powershell: node --version; npm --version

Using cmd: node --version && npm --version

You should receive back output that looks similar to:

2. Install Node-RED

Installing Node-RED as a global module adds the command node-red to your system path. Execute the following at the command prompt:

npm install -g --unsafe-perm node-red

3. Run Node-RED

Once installed, you are ready to run Node-RED.


Alternative Installations on Windows

In this section, we provide you with information on alternative ways to install Node.js, npm and the Windows Build Tools needed to install some Nodes for Node-RED on Windows.

Note : You should not use an administrative (a.k.a. «elevated») command prompt unless specifically instructed to. You will very likely need to be quite familiar with command prompts as you learn about Node-RED and Node.js and it will be worth while reading some of the Microsoft articles on PowerShell. the PowerShell Tutorial and PowerShell One-Liners sites may also be helpful.

Standard installations of Node.js on Windows require local administrator rights. Download the appropriate version from the official Node.js home page. It will offer you the best version. While you can use either 32 bit or 64 bit versions on 64 bit Windows, it is recommended to use the 64bit version of Node. If for some reason, you need a different installation, you can use the Downloads Page.

There are two potentially useful alternatives to installing Node.js with the MSI installer.

  1. Using the Chocolatey package manager

    Chocolatey is a package manager for Windows similar to APT or yum on Linux and brew on the Macintosh platforms. If you are already using Chocolatey, you may want to use this tool to install Node.js (e.g. using the nodejs-lts package). Note however, that many packages have uncertain management and that these packages may use different folder locations than those mentioned above.

  2. Using a Node version manager

    Using a Node.js version manager such as nvm-windows can be very helpful if you are doing Node.js development and need to test against different versions. Keep in mind that you will need to reinstall global packages and may need to re-install local packages when when you switch the version of Node you are using.

Note : Microsoft maintain a parallel version of Node that uses the Microsoft Chakra Core JavaScript engine instead of V8. This is not recommended for Node-RED as it has not been tested.

npm on Windows

When you install Node.js, you are also installing the npm package manager. You may see some instructions on the web that recommend installing later releases of npm than the one that comes with the Node.js release. This is not recommended as it is too easy to later end up with an incompatible version. Node.js releases are very regular and that is sufficient to keep npm updated.

Sharing Node-RED between Users

Node.js is installed into the Program Files folder as you would expect. However, if you install a global package like Node-RED using npm -g, it is installed into the $env:APPDATA\npm folder (%APPDATA%\npm using cmd) for the current user. This is less than helpful if you are installing on a PC with multiple user logins or on a server and installing using an admin login rather than the login of the user that will run Node applications like Node-RED.

Note : To see what a folder name like %APPDATA% translates to, you can simply type it into the address bar of the Windows File Explorer. Alternatively, in PowerShell, type the command cd $Env:APPDATA(cd %APPDATA% using cmd).

To fix this, either give permissions to the folder to other users and make sure that the folder is included in their path user environment variable.

Alternatively, change the global file location to somewhere accessible by other users. Make sure that you use the user that will be running Node-RED to make these changes. For example, to change the location to $env:ALLUSERSPROFILE\npmglobal using PowerShell:

mkdir $env:ALLUSERSPROFILE\npmglobal
npm config set prefix $env:ALLUSERSPROFILE\npmglobal

You will then want to change the npm cache folder as well:

mkdir $env:ALLUSERSPROFILE\npmglobal-cache
npm config set cache $env:ALLUSERSPROFILE\npmglobal-cache --global

If using the above changes, you can add the new prefix folder to the PATH System variable and remove the old folder from the user’s Path variable. To change the PATH Environment variable, type environment into the start menu or Cortana and choose Edit Environment Variables.

For each of the users running Node-RED, check that the above settings for the other users are correct.

Installing Node.js Windows Build Tools

Many Node.js modules used by Node-RED or installed nodes have binary components that will need compiling before they will work on Windows. To enable npm to compile binaries on the Windows platform, install the windows-build-tools module using the command prompt as an Administrator:

npm install --global --production windows-build-tools

If you wish to have the built-in Python v2.7 install exposed for use, use the command:

npm install --global --production --add-python-to-path windows-build-tools

Notes:

  • Not all Node.js modules will work under Windows, check the install output carefully for any errors.
  • During the install some errors may be reported by the node-gyp
    command. These are typically non-fatal errors and are related to optional dependencies
    that require a compiler in order to build them. Node-RED will work without these
    optional dependencies
    . If you get fatal errors, first check that you installed the windows-build-tools module and that you have closed and opened your command prompt window.

Running on Windows

Once installed, the simple way to run Node-RED is to use the node-red command in a command prompt:
If you have installed Node-RED as a global npm package, you can use the node-red command:

This will output the Node-RED log to the terminal. You must keep the terminal open in order to keep Node-RED running.

Note that running Node-RED will create a new folder in your %HOMEPATH% folder called .node-red. This is your userDir folder, think of it as the home folder for Node-RED configuration for the current user. You will often see this referred to as ~/.node-red in documentation. ~ is shorthand for the user home folder on Unix-like systems. You can use the same reference if using PowerShell as your command line as recommended. If you are using the older cmd shell, that won’t work.

You can now create your first flow.

Using PM2

If you are using Windows to develop Node-RED flows or nodes, you may find it helpful to use PM2 to run Node-RED. This can be configured to automatically restart when files change, always keep Node-RED running and manage log output.

Run Node-RED on Startup

If you want to use Windows as a production platform for Node-RED, you will want to have a Windows Task Scheduler job set up. To do so:

  1. Go to the start menu and type “task scheduler” and click on the result.
  2. Click on “Create Task…” in the right-hand menu. Follow the steps to create a new task.

Make sure that you use the user login that you’ve used to set up and do the initial run of Node-RED. You can use an “At startup” trigger to always run Node-RED at system startup. Use the Action “Start a program” with details set to C:\Users\<user>\AppData\Roaming\npm\node-red.cmd (replacing <user> with your actual user name).

You may wish to make sure that it only starts if the network is available. You may also wish to restart if the job fails. Perhaps restarting every minute but only 3 times — if it won’t start by then, the error is fatal and will need some other intervention. You can check for failures by looking in the event log. If you want to access to the logs when running this way, you should amend the node-red.cmd file to redirect std and error outputs to a file (creating an alternative startup file would be better so that it isn’t overwritten on updates).

windows-build-tools is used for some python tools

Summary

If you are a developer working on a Windows machine, you may have encountered issues when building native Node.js modules. This is because some Node.js modules require compilation of native C/C++ code, which typically requires a compiler toolchain to be installed on the machine. The process of setting up a toolchain on Windows can be complex and time-consuming, especially for beginners or those without a background in C/C++ development.

To simplify the process of setting up a toolchain on Windows, Microsoft has released an npm package called windows-build-tools. This package includes the necessary build tools, such as the Visual C++ Build Tools and Python, required to build native Node.js modules on a Windows machine.

Install it with the following command:

1
npm install --global windows-build-tools

With windows-build-tools, developers can easily install and configure the required toolchain with just a few simple commands, saving time and effort compared to setting up the toolchain manually. Additionally, the package automatically sets the necessary environment variables to ensure the tools are available to Node.js when building native modules.

The windows-build-tools package is especially useful for developers working with popular Node.js packages like node-gyp or bcrypt, which require compilation of native code. By simplifying the toolchain setup process, windows-build-tools allows developers to focus on building their applications rather than troubleshooting build toolchain issues.

Overall, the windows-build-tools package is a valuable tool for Windows developers who need to build native Node.js modules. Its ease of use and simplicity make it an attractive option for developers of all levels of experience.

node-gyp is a tool that enables the compilation of native add-on modules for Node in multiple platforms. It has widespread use and is included as a dependency in many NPM packages.

On most systems, this isn’t an issue, and installing node-gyp with the rest of your packages works as expected. Unfortunately, this is not the case with Windows, as is evidenced by this thread from 2015. The Windows environment makes getting node-gyp to work a less-than-stellar developer experience, full of multiple pitfalls and many ways for things to go wrong.

This guide is meant to help solve the issues that can arise when installing a package that requires node-gyp.

1. Try running npm install with the --no-optional flag.

If you’re lucky, the dependency that requires node-gyp will be optional, and you can skip the entire process required to get it working. Try running npm install –no-optional to install only the required dependencies.

If you run this and still get the error, I have bad news: You’re in for a bit of a ride. As we begin our journey into getting node-gyp up and running, here’s an important note for all of the steps that follow. Make sure that you’re always working in an elevated terminal (with administrator privileges) and that you restart your console whenever a download is complete.

2. Try downloading the windows-build-tools package.

According to the node-gyp documentation, this step should be the end-all-be-all solution to fixing node-gyp problems. For most people, that’s true. NPM has a package called windows-build-tools that should automatically install everything you need to get node-gyp working, including the Microsoft build tools, compilers, Python, and everything else required to build native Node modules on Windows.

The good news is that installing this package should take care of all of the wiring up of these components. The bad news is that there are a lot of things included in it.

Depending on the version you download, it can hover between three and eight gigabytes (all to get some dependencies installed!). The install can take upwards of 30 minutes depending on your connection, so don’t despair if it seems like the install is hanging for a while.

You can download them by running this command: npm install --global --production windows-build-tools --vs2015

Important note

If you run this command without any additional flags, you’ll install the files associated with the latest version of Visual Studio, which is VS2017 at the time of writing. However, node-gyp requires the v140 distributable, not the v150 (which comes with VS2017). This is why the --vs2015 flag is added to the end of the command, since that’s the last version of Visual Studio that came with the v140 package. You can see more notes about that near the bottom of the package’s website.

Hopefully, that’s all it will take for you to get everything installed. If you’ve still got issues, then you’re going to have to grab all of the required files manually.

3. Download the Visual Studio 2015 build tools manually.

Rather than installing the build tools through NPM, download them manually. You can find them on the Microsoft download page. Once they’re downloaded, just run the installer.

4. Tell Node to use the 2015 build tools.

Now that we have the build tools, we need to tell Node to use them. You’ll have to run this command: npm config set msvs_version 2015 –global

5. Make sure you have Python 2.7 installed.

Next up is to download Python 2.7. This is important–by default, you’ll install the newest version (3.x.x), but only 2.7 is compatible with node-gyp. If you try to use a newer version of Python, you’ll get a syntax error due to print being made into an actual function in Python 3.

If you have another version of Python already installed, that’s okay. They can coexist with each other. You can grab Python 2.7 at this link.

6. Set your Node config to use Python 2.7.

Now that you have Python 2.7, you’re going to have to set Node to use it by default. To do that, run this command: npm config set python python2.7

If you followed the last few steps, you should now have everything necessary to get node-gyp working. Make sure you’ve restarted your terminal and are running it as an administrator, and try doing your install again. Hopefully, at this point, you can successfully install the dependencies you need. If not, we’re going to have to try one last thing.

7. Repeat Step 2 with the Visual Studio 2017 build tools.

I’ve personally had issues when I’ve tried to download the 2017 version of the build tools, even when trying to use newer versions of node-gyp. If you look online, you’ll see lots of other people with the same problem, including some of the commenters on this StackOverflow question.

However, most of the documentation around node-gyp and compiling native Node modules on Windows doesn’t specify to use the --vs2015 flag, and some even mention downloading the 2017 version. If you’re still having issues with getting node-gyp to run, try repeating Step 2 while omitting the --vs2015 flag.

8. Try installing an older version of Node.

Still getting an installation error? Try installing an older version of Node. If you’re on an experimental version, try going back to the last stable release (and then make sure that you’re actually using that version when you try and do npm install).

If that still doesn’t work, try going back to Node 8. You’ll find some issues online of people having issues with Node 10 that were resolved by downgrading to Node 8, and sometimes newer versions of Node don’t play nice with node-gyp.

9. File an issue.

If you’re still having trouble getting node-gyp to work, then your issue probably doesn’t fall into one of the more common problems. It’s worth doing some research online to see if that solves your problem. Otherwise, your best option is to file an issue on the GitHub page for node-gyp and see what advice you can get there.

Other Resources

Much of this information can now be found on the GitHub readme for node-gyp, but it wasn’t always there. It only made an appearance after a few thousand posts from disgruntled Windows users who just wanted to install some dependencies. Even then, the information is missing some of the issues that arise with installing the wrong version of the build tools.

Another great resource is Microsoft’s guide on working with Node on Windows. It even has sections dedicated to compiling native Node modules and resolving basic node-gyp problems.

Additionally, this question on StackOverflow contains useful answers and comments regarding this issue. Leave a note in the comments if you’ve found anything else helpful in solving node-gyp issues!

A well-prepared young man ready to start running. Cover photo by William Stitt on Unsplash.

Updated for Angular version 11.0.

Are you struggling with setting up an Angular development environment on Windows? Let us get you up and running in no time!

In November 2018, I attended ngHeroes as a mentor. It excited me to help students and people from other industries who wanted to learn web development with Angular. A lot of them wanted to start a new career. I was happy to notice more female attendance than I expected based on the gender gap in our industry.

I started my career as a software developer 7 years ago, but I did not forget what it was like to be new to programming. What I did forget was how much work we need to do to get up and running with the necessary tools.

The ngHeroes students had macOS, Linux, and Windows computers. We managed to get them up and running but hit some bumps along the way. In this article, I will focus on installing the tools and dependencies you need to develop Angular applications on a Windows machine. They are almost the same for other operating systems. Only the build tools step should differ.

If you run into trouble, comment on this article.

1. Node.js

Node.js

We use Node.js as a JavaScript runtime for many web development tools.

The first thing you need to install is Node.js. It is a JavaScript runtime that can run web servers, scripts, and console applications. A lot of web development tools use Node.js.

Go to the Node.js website. It offers you 2 installation packages based on your operating system and CPU architecture: LTS (Long-Term Support) and Current.

This is where it gets tricky. LTS is the right choice, but we might need an older LTS version. We need a version of Node.js LTS that the Angular CLI (Command-Line Interface) supports. Angular CLI is a development tool for Angular projects.

Figure 1. Node.js support in Angular CLI. Open in new tab.

For a new application, we can pick the newest version of Angular CLI. On jsDelivr, we can read the package details for the latest version of Angular CLI. At the time of writing, this is Angular CLI version 11.0. In the package details, we can also see the supported version of Node.js.

Towards the end of the JSON file, you will find a JSON object named "engines" and inside of that you will find the requirements for "node". For example, it says "node": ">= 10.13.0" for Angular CLI version 11.0. This means that we need at least version 10.13 of Node.js.

As seen in Figure 1, Angular CLI version 11.0.x has official support for Node.js versions 10 and 12.

We decided to use the newest Angular CLI. Let us go back to the Node.js website, download the installer for the latest LTS version supported by Angular CLI and run it with administrative privileges.

If you are asked whether to include Boxstarter or Chocolatey in the installation, do include it. More on that in a minute. Please give it time to finish installing. It might take a while and it could even require a reboot.

To verify that Node.js is installed, open a terminal (command prompt) and run node --version which displays the installed version of Node.js.

2. Windows Build Tools

PowerShell showing Windows Build Tools being installed

Installing Windows Build Tools with NPM CLI.

We decided to use the newest version of Angular CLI, but before we can install it, we need to take care of more dependencies.

To be specific, some compilation tools are used by the package node-gyp for pre and post install tasks for various packages such as Angular CLI.

For Windows, we need Python 2.7, Visual Studio Build Tools, and C++ Build Tools. Luckily, we can install them all as a single package using the NPM CLI.


If you previously installed Node.js with the Boxstarter or Chocolatey option included, you already have these dependencies. Skip to step 3.


Run the following command to install all the Windows-specific dependencies for Angular CLI. It uses the NPM (Node Package Manager) CLI to install from the NPM Public Registry. You installed NPM CLI with Node.js.

Make sure to use a terminal with administrator privileges. For example, right-click Command Prompt and choose “Run as administrator”.

NPM is like Composer (PHP), LuaRocks, Maven (Java), NuGet (.NET), pip (Python), and RubyGems, but for JavaScript.

npm install --global --production windows-build-tools

Enter fullscreen mode

Exit fullscreen mode

Wait until the installation finishes. It will say “All done!”


Installing the build tools should be the only step that differs from other operating systems than Windows. For example on Ubuntu and Debian you’ll run the command sudo apt install gcc g++ make python2.


3. Angular CLI

The Angular CLI logo

Angular CLI is a development tool for Angular applications.

Now we are ready to install Angular CLI. As before, we use NPM CLI to install it.

npm install --global @angular/cli

Enter fullscreen mode

Exit fullscreen mode

To verify that Angular CLI is installed, run the command ng --version which displays the installed version of Angular CLI and its dependencies.

4. Git

Git is a popular distributed version control system

We are almost ready to create a new Angular application project. Before we can do that, we need a version control system to be able to back up our source code to a server. It will also enable us to create checkpoints in time that we can return to if we get stuck.

I suggest Git which has excellent support in the code editor we are going to use. Git is also well-integrated with Angular CLI.

Go to the Git website. It will offer you an installation package based on your operating system.

5. Visual Studio Code

IntelliSense in an Angular component template

The Angular Language Service extension for Visual Studio Code adds IntelliSense to Angular templates.

We need a code editor to develop our Angular application. Visual Studio Code is a free code editor offered by Microsoft. It has excellent Angular and TypeScript support through extensions. Visual Studio Code supports Linux, macOS, and Windows.

Install and run the Stable Build from the Visual Studio Code website.

Make sure to install the Angular Language Service extension afterwards. It will add IntelliSense to your Angular templates.

Scaffold an Angular application

With all the tools installed, we can finally scaffold an Angular application. Open a command prompt and navigate to the directory that you want to create the project in.

Use the following Angular CLI command to create the necessary directory and files for a new Angular application. Replace my-app with the name of the application which will also be the name of the directory that Angular CLI creates.

By the way, don’t use a directory path that contains a space such as C:\Program Files (x86)\Angular. The Angular CLI development server has issues with serving static files that have a path containing spaces. Instead, choose a path such as C:\Projects.

ng new my-app

Enter fullscreen mode

Exit fullscreen mode

Angular CLI will ask you whether want routing. Most single-page applications (SPAs) will use routing. If this is your first time working with Angular, you can skip it by answering n (no).

You will also be prompted to select a stylesheet format. CSS is the native browser format. SCSS is the most popular stylesheet preprocessor. Pick the one you have experience with, or simply CSS if you are new to web development.

The installation will take a few minutes since it installs a lot of tools and library dependencies that are used by Angular and Angular CLI.

Time to start coding

The Angular.io home page cover

Time to start developing an Angular application. Try out the “Getting started with Angular” tutorial on Angular.io.

Now you have everything you need to start coding! Open the project directory with Visual Studio Code.

When developing your application, you will want to open a development web server. Angular CLI has prepared one for you which you can run with the following command from inside the root project directory.

npm start

Enter fullscreen mode

Exit fullscreen mode

which is an NPM script shortcut for

ng serve

Enter fullscreen mode

Exit fullscreen mode

Once the development server has finished compiling your application, you can open it in a browser by navigating to http://localhost:4200.

Every time you change a file and save it, your browser will refresh and show you the changes.

To stop a running development server, you have to press Ctrl+C, type y and hit Enter.

Angular CLI defined the start script in package.json. Try adding the --open flag to the script so that it becomes ng serve --open, then save package.json and run the server again with npm start.

Now, all you have to do is develop your application. If you lack ideas or confidence in your development skills, try the “Getting started with Angular” tutorial on Angular.io.

Additional learning resources

Read the guide “Version Control in Visual Studio Code” to learn about version control with Git in Visual Studio Code.

Angular.io has development guides for most of the Angular framework.

The Angular CLI can help you scaffold components, directives, Angular modules, pipes, and services. Find out more in the Angular CLI documentation.

Remember to back up your source code by committing and pushing your Git repository. GitHub, GitLab, and Bitbucket offer free private Git repositories for individuals.

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Windows 10 удалил файлы после обновления
  • Download nexus for windows 10
  • Wexler 10 windows 10
  • Bcrypt dll windows xp 32 bit
  • Кнопка гибернации на рабочем столе windows 10