Web Devlopment Using NodeJS
Posted By : Karan Bhardwaj | 26-Mar-2015
Decription:
NodeJS is an open source, cross platform run time environment for server side and networking applications.NodeJS is truly based on Javascript.NodeJs is powerful run time environment to develop web-application,websites,network applications etc. NodeJs is a latest,powerfull and advanced technology to develop all types of web applications on server side and all types of networking applications. NodeJS uses Google V8 Javascript Engine to execute code.
Steps to create a demo-based website using NodeJS:
1 ) First of all you need to install nodejs in your system and create a directory where you want to install below node modules.
2 ) After all that you need to install the following node modules in your project folder.
a ) Express :
You can install this node module by the following below command in your project folder.
sudo npm install express
Express is the web frame-work that everything else is built on.
b ) Express-Stormpath :
You can install this node module by the following below command in your project folder.
sudo npm install express-stormpath
Provides convenience features that can be tied in to the Express app, making it very easy to use Stormpath’s features in Express.
c ) Jade :
You can install this node module by the following below command in your project folder.
sudo npm install jade
It is a templating engine for writing HTML pages.
3 ) Now by using the below command in your terminal create a package.json file in for your project and fill the necessary details for your project in that file.
npm init
4 ) Now by using the below command you can install, save and link the above all modules to your package.json file.
sudo npm i --save express express-stormpath jade
5 ) It's time to create a server coding and configurations for your project by using node modules. For this create a file named as app.js by using the below command.
touch app.js
6 ) Open that app.js file in your text editor and paste below code in your file.
var express = require('express'); var stormpath = require('express-stormpath'); var app = express(); app.set('views', './views'); app.set('view engine', 'jade'); var stormpathMiddleware = stormpath.init(app, { apiKeyFile: '../mywebapp/apiKey-6ZZHTAAL3SUAXK0YHO9I9KKEV.properties', application: 'https://api.stormpath.com/v1/applications/3uHST1jg5NqpW0bDFETNnc', secretKey: 'dsfsdfasfasfsadfsdfdsfds', expandCustomData: true, enableForgotPassword: true }); app.use(stormpathMiddleware); app.get('/', function(req, res) { res.render('home', { title: 'Welcome' }); }); app.listen(3000);
In this we have to specify the api-key for your project of express-stormpath.To create the api-key you have to create account in express-stormpath development account.applicaton is also defined in your dashboard and secret key is a random string used for encryption purpose. In the above code we specified the view engine and its path.
7 ) Now it's the to create html view part for your project, for that create a folder views and in that folder create a file named as home.jade and put following jade html code in that file.
html head title=title link(href='//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css', rel='stylesheet') body div.container div.jumbotron h1 Hello! if user p Welcome, #{user.fullName} p a.small(href="profile") Edit my profile a.btn.btn-primary(href="/logout") Logout else p Welcome to my app, ready to get started? p a.btn.btn-primary(href="/login") Login now p span.small Don't have an account? span a.small(href="/register") Register now
8 ) Now run your project by the foolowing below command.
node app.js
9 ) Now if you want to do any change in your project and you don't want to restart your server again and again, for that you have to install the following node module in your system by the following command.
sudo npm install -g nodemon
After this do any changes in your project and get your instant output without restarting your node server.
THANKS
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Karan Bhardwaj
Karan is expert in JavaScript, JQuery, Phonegap, Java, Groovy and Grails, SpringBoot, Kurento, MongoDB, NodeJs, Wowza, FFmpeg and Kaltura.