How to create an app in Node.js

in Node.js / 1 Comment

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

How to create an app in Node.js by Anil Kumar Panigrahi

Installation:

We have discussed it earlier Foundation front-end framework installation

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

With more than 9 years experience in PHP and Founder of Anil Labs, a blog for PHP and related posts. contributed posts regarding CodeIgniter, CakePHP and Learn PHP online ...Contact : [email protected]

Discussion 1 Comment

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>