This tutorial is a really quick and simple way to get a Node Express web server running on your machine for local Angular development, or for whatever other JavaScript frameworks you prefer. You could even just use this basic Node web server to host static files. The point here is to help get you up and running quickly!

Assumptions and Resources

Step 1: Install Express Package

Open up terminal, let’s create a new project directory and install Express.

$ mkdir myapp
$ cd myapp
$ npm install express

Step 2: Create Express Web Server

Create a file named server.js and add the following code:

var path = require('path');
var express = require('express');
var app = express();

var staticPath = path.resolve(__dirname, './');
app.use(express.static(staticPath));

app.listen(3000, function() {
  console.log('please visit: http://localhost:3000');
});

Step 3: Create Angular App

Create a file called index.html and add the following markup:

<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body ng-controller="appCtrl">
	<h1>hello </h1>

	<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.3/angular.min.js"></script>
	<script src="app.js"></script>

</body>
</html>

Next, create file named app.js and add the code below:

var app = angular.module('myApp', []);

app.controller('appCtrl', function($scope) {
	$scope.name = 'Steve';
}); 

Step 4: Run it!

Go to your terminal and run:

$ node server.js

And finally open up a brower and visit http://localhost:3000