Skip to main content

Node.Js-First Code

Node.Js is server side JavaScript platform build on Google Chrome's JavaScript Engine. Most of the companies are developing their applications with Node.js, for example You Tube, Yahoo, Paypal etc. Node.js applications are written in JavaScript and can run with any OS(Operating) under Node.js runtime environment.

The Node.Js tutorial on Techtuts gives clarification about the Node.Js from the fundamental concepts to improved concepts. This tutorial provides good understanding about the Node.Js for Technical, Non-Technical People, College Students and Working Professionals. Given an examples are an easy to understandable and an easy to practice by yourself.

In this tutorial you will grasp about the concepts from start to end. This tutorial includes an introduction, features, Node Package Manager, Environment Setup, Callbacks, Event Emitter, Modules, Filesystem, Streams, Buffers, Rest API Creation etc.

we are going to create  our first program with nodejs.

Create your first Program/application

Nodejs is one the part of mean stack development. We are going to Create your first programme in Node.Js to display the 'Hello, World!' in  Browser. It is a simple example for Node Js API and application. This is the  first step for creating a Web and Networking applications using Node Js.

First Program in NodeJs

Create a Node.js file named "nodejstutcode1.js", and add the following code:


const http = require('http');
const hostname = '127.0.0.1';
const port =3000;

const server = http.createServer((req,res) => {
    res.statusCode =200;
    res.setHeader('Content-Type','text/html');
    res.end('Hello, World!\n');
});

server.listen(port, hostname, ()=>{
    console.log(`Server running at http://${hostname}:${port}/`);
});

Now execute the nodejstutcode1.js to start the server as follows

NodeJs1 Console

− Verify the Output. Server has started.

NodeJs Code 1