Skip to main content

Posts

Showing posts with the label Node Js

How to implement routing in Nodejs

A route is a mapping from a url to an object.It handles HTTP client requests. Basic Routing Hope you have install and have basic knowledge Express module. npm install express Note: Above command download the required express modules and install them. Here is our Server file. var express = require( 'express' ); var app = express(); //Creating Router() object var router = express.Router(); // Provide all routes here, this is for Home page. router.get("/",function(req,res){   res.json({"message" : "Hello World"}); }); app.use("/",router); // Listen to this Port app.listen(3000,function(){   console.log("Live at Port 3000"); }); Code Explanation: 1. In our first line of code, include the "express module." 2. Create object of the express module. 3. Creating a callback function. This function call when you hit url from browser http://localhost:3000 .It send the string 'Hello World' to ...

How to learn NodeJs in 5 steps

NodeJs Entry level Tutorial Node.js is an open-source, cross-platform JavaScript runtime environment for developing a diverse variety of tools and applications. It is a server-side platform built on Google Chrome's JavaScript Engine Follow Basic steps to run your first example Step1: Download Nodejs and install it. Step2: After installation Check NodeJs working or not a) Open Windows Command Prompt b) Execute the Command node -v. It print a version number Example: C:\Users\Sudhir>node -v Output: v6.9.2 c) Execute the Command npm -v . It print NPM’s version number Example: C:\Users\Sudhir>npm -v Output: 3.10.9 Step3: Type npm init and press enter Step4: It will ask for file name, version and description etc Step5: It will create a package.json file { "name": "nodetest", "version": "1.0.0", "description": "Hello test", "main": "index.js", "scripts": { ...