Hello world application using nodejs and express – onlinecode

Hello world application using nodejs and express – onlinecode

In this post we will give you information about Hello world application using nodejs and express – onlinecode. Hear we will give you detail about Hello world application using nodejs and express – onlinecodeAnd how to use it also give you demo for it if it is necessary.

In this article, we will learn how to create a hello world simple node js application in our application using node js and express. Nodejs is open source framework it used the javascript server and it is run on different os like as Windows, Linux, Unix, and Mac, etc. so first we will check the node is install or no in our system, if not in our system, then after we will go to follow below Url and install node js.

Let’s go and follow the below step for how to display hello world in our application using node js and exress.js.

Step 1: Create the Application Directory.

First, we will open the command prompt and create the application directory. for this, you can follow the below command.

PHP
mkdir myapp
cd myapp

Step 2: Create an application using npm init

The “npm init” command through we can create a new package.json file in our application directory. when we build a new app at that time we use this command. Node.js will need to have a package.json file because includes the application related packages and application data.

Here below command helps to initialization our application.

PHP
npm init

This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See 'npm help json' for definitive documentation on these fields
and exactly what they do.

Use 'npm install <pkg>' afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (myapp) myapp
version: (1.0.0)
description: myapp
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to E:test_macmyapppackage.json:

{
  "name": "myapp",
  "version": "1.0.0",
  "description": "myapp",
  "main": "index.js",
  "scripts": {
    "test": "echo "Error: no test specified" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

Is this OK? (yes) yes

Step 3: Install Express Package

Expess.js is a free and open-source framework and it’s a web application framework for Node.js. we can manage routes, create restful API, handle the request and response, and also create MVC structure using the express.js. Npm stands for the node package manager. npm, help to install node packages and manage the types of dependencies.

Here below command help to install express package.

PHP
npm install express --save

Step 4: Create New File and Save

First, we will make a new file and paste follow the below code in our file and save as app.js.

PHP
var express = require('express');
var app = express();
app.get('/', function (req, res) {
  res.send('Hello World!');
});
app.listen(3000, function () {
  console.log('application listening on port 3000!');
});

Step 5: Run Our Application

Finally, We will run our application using the below command.

PHP
node app.js

Please follow and like us:

Hope this code and post will helped you for implement Hello world application using nodejs and express – onlinecode. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

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

88  +    =  96

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US