Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

The Node.js -- Part5: Node Module Basics

node node.js module node module basics

  • Please log in to reply
No replies to this topic

#1 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 19 February 2013 - 02:00 AM

So far we know how to install node modules by npm and how to use them in our application. Today we will learn how to create our first node module. 
 
Concept of Node Modules
Node modules are simply javascript files containing some functions created for some specific tasks. Lets see an example
 
var http = require('http'),
    util = require('util');
 
var server = http.createServer(function (req,res){
    util.log('Hello world');
    res.end('Hello world');
});
 
server.listen(8080);
util.log('Server listenning at localhost:8080');
Here we have used the http module that has some functions like createServer(), listen() etc. These functions are used for some specific purpose. The util module is used for just showing message with the current timestamp.

Don't forget to check out our other node.js content!

Attached Files


Edited by Roger, 19 February 2013 - 02:45 PM.
added links

  • 0





Also tagged with one or more of these keywords: node, node.js, module, node module, basics