Add node server with an Angular app (Run angularjs app with node server)

Shubham Verma
2 min readDec 18, 2017

--

Step 1: I hope you have created your angularJS app. Which started running after double-clicking on index.html.

Your Angularjs app directory is here :

AngularApp->myApp->
AngularApp->myApp->controllers
AngularApp->myApp->views
AngularApp->myApp->services
AngularApp->myApp->app.js
AngularApp->myApp->index.html

Step 2: Now to add node server:

Create a package.json file and insert below code in it:

(Location : AngularApp->package.json)

{
“name”: “myApp”,
“version”: “0.0.1”,
“description”: “My Project”,
“dependencies”: {
“express”: “*”
},
“engine”: “node >=0.6.x”,
“scripts”: {
“start”: “node server.js”
},
“main”: “server.js”,
“repository”: {
“type”: “git”,
“url”: “”
},
“author”: “myApp”,
“license”: “myApp”,
“bugs”: {
“url”: “”
},
“homepage”: “/”
}

Step 3: Create server.js:
(Location: AngularApp->server.js )

var express = require(‘express’);
var app = express();
app.use(express.static(“myApp”)); // myApp will be the same folder name.
app.get(‘/’, function (req, res,next) {
res.redirect(‘/’);
});
app.listen(8080, ‘localhost’);
console.log(“MyProject Server is Listening on port 8080”);

Step 4: Run command ‘npm install’ after navigating to the package.json file.

Step 5: Run command ‘npm start’. Open a browser and hit localhost:8080/

And enjoy your app.

Read in details.

If you want to add node server in angularJs app from scratch then this link will help you a lot.

If you want to serve React application using the Node server, then this article will help you a lot.
If you’re interested in Node.js or JavaScript, then this link will help.

Thank you for taking the time to read this article. If you like and learned something from this article, click the 👏🏻 icon so other people will see this here on Medium.

--

--

Shubham Verma

A full-stack developer, In my free time, I write blogs and play guitar. I am both driven and self-motivated.