About Us
IDKBlogs

  All  
Javascript
NodeJS
AngularJS
Angular2+
ReactJS
Others

Serve angularJs application by Node server.

  idkblogs.com      June 27, 2020

Shubham Verma

Shubham Verma


Serve angularJs application by Node server.

In this article, we will create an angularJs app and then we will create a node server. and the node server will run our angularJs app.
Adding node server or running node server at the top of angularjs app is very easy and its help us to angularjs app deployment. After implementing the node server, our angularJs app will run after server start. You need to just do npm start, and you're done.

Let's get started

What we will do in this article:
* Create an angularJs simple app.
* Create a nodeJs server.
* Run node server and our angularJs app will run.

Create an angularJS app:

We will create a directory "AngularApp" and inside we will create our angulasJs app in directory "myApp".

Create a index.html (AngularApp/myApp/index.html) file and write below code:

index.html

Create a app.js (AngularApp/myApp/app.js) file and write below code:

app.js:


Now, we have created an angularjs app. Now if you click on index.html then your angularjs app will be started.
Now let's create a node server.



Create a node server:

Now create a package.json file inside AngularApp (root) directory and write the below codes:


package.json

Now its's time to create a server.js file in AngularApp (root) directory

server.js

Now we have created a node server, which will be run on port "8080".
Let's install the dependencies:

Open terminal/CMD and locate you root location and run below command:

npm install
Add node server with an Angular app

Add node server with an Angular app: npm install

After successful npm install, run the command "npm start":

npm start
Add node server with an Angular app

Add node server with an Angular app: npm start

After npm start you can see the message:

MyProject Server is Listening on port 8080

The above message shows that our node app is running successfully, Now open the browser and hit the URL "localhost:8080" and see the result:

Add node server with an Angular app

Add node server with an Angular app: npm start

You can see, the angularJs app is running on port 8080, it means our node app is running on port:8080 and this node server serving the angularJS app.

Conclusion:

In this article, we have created an angularjs app and then we have created a node server. after we run our node server and this node server is serving the angularJS app


Thank you

for taking the time to read this article. If you’re interested in Node.js or JavaScript this link will help you a lot.



Copyright © 2020 IDKBlogs | All Right Reserved

About Us

Powered by : IDKBlogs

Last Update : 19/09/2020