Skip to content

This git repository provides a simple static file server built with pure Node.js without the use of a framework

Notifications You must be signed in to change notification settings

RahulRawat1994/nodejs-without-plugins

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nodejs-without-plugins

This git repository provides a simple static file server built with pure Node.js without the use of a framework

index.js

var http = require('http');
var routes= require('./routes');

/**
 * Starting Server 
 */
http.createServer(function (req, res) {

  routes.getView(req.url,function(html){
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write(html);
    res.end();
  });
  
}).listen(8000);
console.log('Application started on 8000');

routes.js

var fs = require('fs');

/**

  • This function return view of specific url
  • @param {string} url url string
  • @returns {callback} html content. */

exports.getView = function (url, callback) {

var filepath='';

switch(url) {
    case '/home':
        filepath='home.html';
        break;
    case '/about':
        filepath='about.html';
        break;
    default:
        filepath='default.html';
}

fs.readFile(filepath, function(err, data) {
    callback(data);
});

};

About

This git repository provides a simple static file server built with pure Node.js without the use of a framework

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published