Wednesday, 1 March 2017

How to create an app in Node.js


Last few days back I have worked on Node.js. So I would like to explain in this post about how to create an app in Node.js.

What is Node.js:

Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js’ package ecosystem, npm, is the largest ecosystem of open source libraries in the world.
Source : https://nodejs.org/en/
How to create an app in Node.js by Anil Kumar Panigrahi

Installation:

We have discussed it earlier Foundation front-end framework i
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
download link for How to create an app in Node.js by Anil Kumar Panigrahi

Application:

1. Create application folder eg: SampleApp
2. Create a package.json
eg:
{
  "name": "SampleApp",
  "description": "SampleApp using Node.js",
  "version": "0.0.1",
  "private": true,
  "main": "app.js",
  "dependencies": {
    "express": "4.9.5"
  }
}
dependencies – list of modules used in this application

Create a file with .js extension

eg: app.js
app.js code:
var express = require('express');

var app = express();

app.get('/', function (req, res) {
  res.status(200).send('Welcome to Anil Labs first node.js sample application!');
});

// Start the server
var server = app.listen(3000,function(){
 console.log("Listening to port %s",server.address().port);
});

Run the application:

cd SampleApp
npm install
node app.js

No comments:
Write comments

Services

More Services

© 2014 Today-Health. Designed by Bloggertheme9 | Distributed By Gooyaabi Templates
Powered by Blogger.