Serve angularJs application by Node server.

🙋‍♂️ Shubham Verma    🗓 June 27, 2020


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



Support our IDKBlogs team

Creating quality content takes time and resources, and we are committed to providing value to our readers. If you find my articles helpful or informative, please consider supporting us financially.

Any amount (10, 20, 50, 100, ....), no matter how small, will help us continue to produce high-quality content.

Thank you for your support!




Thank you

I appreciate you taking the time to read this article. The more that you read, the more things you will know. The more that you learn, the more places you'll go. If you’re interested in Node.js or JavaScript this link will help you a lot.

If you found this article is helpful, then please share this article's link to your friends to whom this is required, you can share this to your technical social media groups also. You can follow us on our social media page for more updates and latest article updates.
To read more about the technologies, Please subscribe us, You'll get the monthly newsletter having all the published article of the last month.