I have started writing tips on my different blog instead of this one. Make sure to follow that one so that you can get latest updates. Here is the link- StackBlogger: Tips and Tricks about Programming
Also follow my another Blog where I write how to make money online, tips about blogging, content creation etc. Here is the link- FlexiPlanet: A hub for Content Marketing.
In my previous post, we learnt how to create an AngularJs Routing app.
Now we will learn to create a Node server app which will serve the AngularJs Routing app. Lets have a quick focus on Node: Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast and scalable network applications. To learn NodeJs in depth, follow the link.
I assume you have already installed NodeJs at your machine.
Steps to create the Node server is as follows:
- Open Command Prompt and paste the below command to install “Express-Generator” at your machine. To learn more about this package, follow the link.
npm install express-generator -g
- Now create a new folder named “test-app” anywhere in your drive.
- Open Command Prompt and go to your newly created folder path ie: “test-app“.
- Run below commands at Command Prompt to create a basic Node-Express app.
express myapp cd myapp npm install
- Create an Angular Routing app. Follow my previous post to create Angular app.
- Copy all the files created from my previous post to the “public” folder in “test-app“. Refer below screen:
- Go to “routes” folder from root and edit the “index.js” file. Replace the code of “index.js” file with below code:
var express = require('express'); var router = express.Router(); /* GET home page. */ router.get('/', function(req, res, next) { res.sendFile('/index.html'); }); module.exports = router;
- Open Command Prompt and go to the root directory of Node-Express “test-app” app which we created earlier and run the below command.
npm start
Refer Screen below:
- Go to your browser and open http://localhost:3000/#/. You can see the output as:
- That’s all.
Thanks for reading. 🙂