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

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

Installation:

We have discussed it earlier Foundation front-end framework installation

1
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
1
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:

1
2
3
4
5
6
7
8
9
10
{
  "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:

1
2
3
4
5
6
7
8
9
10
11
12
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:

1
cd SampleApp
1
npm install
1
node app.js
Categories: Node.js

3 Comments

Deploy Node.js application to Heroku - Anil Labs · August 30, 2016 at 5:37 am

[…] the earlier post, created the node.js sample application. Now we will learn how to deploy node.js application to Heroku. Installation process I have checked […]

How to fetch the URL in React.js application - Anil Labs · December 28, 2018 at 2:49 pm

[…] I have explained how to create Node.js and how to deploy. Now for React.js We need to run the below command to create an […]

How to create or generate QR code using Node.js - Anil Labs · August 25, 2020 at 3:39 am

[…] we are going to create or generate it 1. As earlier explained about install the Nodejs in your system. 2. How to install the packages To install any packages we have to follow below […]

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *