How to Create A Node.js Application using npm tool in Microsoft Windows

Posted on

Introduction

In order to create a new application using node framework, there are several things that must be exist in the first place. It is the existance of the file with the name of ‘package.json’. But in order to create the file itself, it must be going through a certain process. In order to create or to generate ‘package.json’ file as the Node.js application description file, just do it with the help of ‘npm’ tool. That tool itself exist as a command for further execution through the command prompt. According to the information in this link, the package.json file itself is a core to the Node.js application ecosystem.  It is a basic part of understanding and working with Node.js, npm, and even modern JavaScript. The file itself is used as what equates to a manifest about applications, modules, packages, and more. As an addition, it is a tool to that’s used to make modern development streamlined, modular, and efficient.

Creating a package.json file to initialize a Node.js Application

As a developer in the Node.js ecosystem, understanding the basics of package.json is one of the first steps to really kicking off your development experience with Node.js. Because of how essential for understanding the basics of package.json is to development with Node.js, the first thing to do is to create or to generate it. The following is the command to achieve it :

npm install -y

The following is the output of the above command execution :

C:\node\app>npm init -y
Wrote to C:\node\app\package.json:

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

The above output command execution is an output of the command execution ‘npm init -y’. After executing the command itself, it will actually create a file with the name of ‘package.json’. The following is the actual list inside the folder where the file exist :

C:\node\app\server>dir
Volume in drive C is Windows
Volume Serial Number is E003-3593

Directory of C:\node\app\server

04/16/2020 08:48 AM <DIR> .
04/16/2020 08:48 AM <DIR> ..
04/16/2020 08:48 AM 220 package.json
1 File(s) 220 bytes
2 Dir(s) 195,068,497,920 bytes free

C:\node\app\server>

The following is the actual content of the file with the name of ‘package.json’ :

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

The content of the file itself is similar with the output of the command execution of ‘npm init -y’. As the file ‘package.json’ exist, the execution or the initialization for further develop an application using Node.js can continue on.

Leave a Reply