Type Here to Get Search Results !

Basic rest API of Node js with livereload with Gulp

Create a folder in your desired location for start a project and open that in win OS press Alt + D that will focus address bar of folder exporer type cmd and press enter a command prompt open.
  npm init
  npp install express or npp install -g express
create start.js file in root of app. put the following code in that
  var express = require('express');
  var app = express();
  app.get('/', function(req, res) {
  res.send("<html><body><h1>Hello World</h1></body></html>");
  });
  var server = app.listen(3000, "100.100.7.117", function(){
  var host = server.address().address;
  var port = server.address().port;
  console.log("Example app listening at http://%s:%s", host, port)
  });
    
to make live reload

npm install --save-dev gulp gulp-livereload gulp-notify gulp-nodemon express
    
  // Dependencies
  var gulp = require('gulp');
  var nodemon = require('gulp-nodemon');
  var notify = require('gulp-notify');
  var livereload = require('gulp-livereload');
    
  // Task
  gulp.task('default', function() {
    
  // listen for changes
  livereload.listen();
    
  // configure nodemon
  nodemon({
    
  // the script to run the app
  script: 'app.js',
  ext: 'js'
  }).on('restart', function(){
    
  // when the app has restarted, run livereload.
  gulp.src('app.js')
  .pipe(livereload())
  .pipe(notify('Reloading page, please wait...'));
  })
  })
    

Post a Comment

1 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
  1. This comment has been removed by a blog administrator.

    ReplyDelete

Top Post Ad

bogger post ad 1

Below Post Ad

bogger post ad 2

ezoic

Ads Section