Search code examples
javascriptnode.jsnpmpackage

Error in package creation with npm init in Node Js


I just started learning NodeJs from tutorialspoint(TP).

When I tried exactly what they said in this link,

That is , to create a package

C:\Program Files (x86)\nodejs>npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sane defaults.

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

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

Press ^C at any time to quit.
name: (nodejs) VirdWAitJS
version: (1.0.0) 2.0.1
description: VirdWAitJS is an Open Source JavaScript Library meant for DOM Querying
entry point: (index.js) virdwaitjs.js
test command: hello world
git repository: https://www.github.com/virdwait/virdwaitJs
keywords: virdwait, virdwaitJS, DOM Query, VDJS, VD
author: SAGAR V
license: (ISC) MIT
About to write to C:\Program Files (x86)\nodejs\package.json:

{
  "name": "VirdWAitJS",
  "version": "2.0.1",
  "description": "VirdWAitJS is an Open Source JavaScript Library meant for DOM Querying",
  "main": "virdwaitjs.js",
  "dependencies": {
    "npm": "^2.7.4"
  },
  "devDependencies": {},
  "scripts": {
    "test": "hello world"
  },
  "repository": {
    "type": "git",
    "url": "https://www.github.com/virdwait/virdwaitJs"
  },
  "keywords": [
    "virdwait",
    "virdwaitJS",
    "DOM",
    "Query",
    "VDJS",
    "VD"
  ],
  "author": "SAGAR V",
  "license": "MIT"
}
Is this ok? (yes)

When I press the Enter button, I am getting the following error.

npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\Program Files (x86)\nodejs\\node.exe" "C:\Program Files (x86)\nodejs\node_modules\npm\bin\npm-cli.js" "init"
npm ERR! node v0.12.2
npm ERR! npm v2.7.4
npm ERR! path C:\Program Files (x86)\nodejs\package.json
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! Error: EPERM, open 'C:\Program Files (x86)\nodejs\package.json'
npm ERR! at Error (native)
npm ERR! { [Error: EPERM, open 'C:\Program Files (x86)\nodejs\package.json']
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! path: 'C:\Program Files (x86)\nodejs\package.json' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\Program Files (x86)\nodejs\\node.exe" "C:\Program Files (x86)\nodejs\node_modules\npm\bin\npm-cli.js" "init" npm ERR! node v0.12.2
npm ERR! npm v2.7.4
npm ERR! Uncaught, unspecified "error" event.
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! https://github.com/npm/npm/issues
npm ERR! Please include the following file with any support request:
npm ERR! C:\Program Files (x86)\nodejs\npm-debug.log


Solution

  • You are trying to create a project inside a system folder C:\Program Files (x86)\nodejs for which you need administrator password.

    You can open your cmd as administrator and then you'll be able to init your project there.