Home > Node.js > How to create an app in Node.js

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

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
You may also like
Maintenance page for Heroku hosted applications
How to fetch the URL in React.js application
Sending HTML template emails using SMTP in NodeJS
Deploy Node.js application to Heroku

2 Responses

  1. Pingback : Deploy Node.js application to Heroku - Anil Labs

  2. Pingback : How to fetch the URL in React.js application - Anil Labs

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.