I’m trying to install some packages to my shared hosting account on namecheap servers,
I’m a complete begginer with node Js so please bare with me if this is a stupid quetion,
I initially tried to install two packages express & https
through the command line interface in CPanel, these two seemed to have installed, but it gave a warning about the package.json file.
The output is below
[letlziml@premium88 ~]$ npm install express
bash: npm: command not found
[letlziml@premium88 ~]$ cls
bash: cls: command not found
[letlziml@premium88 ~]$ source /home/letlziml/nodevenv/rootz/12/bin/activate
[rootz (12)] [letlziml@premium88 ~]$ cls
bash: cls: command not found
[rootz (12)] [letlziml@premium88 ~]$ cd /home/letlziml/rootz
[rootz (12)] [letlziml@premium88 rootz]$ npm install
ln: creating symbolic link `/home/letlziml/nodevenv/rootz/12/lib/package.json': No such file or directory
npm WARN saveError ENOENT: no such file or directory, open '/home/letlziml/nodevenv/rootz/12/lib/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/home/letlziml/nodevenv/rootz/12/lib/package.json'
npm WARN lib No description
npm WARN lib No repository field.
npm WARN lib No README data
npm WARN lib No license field.
audited 88 packages in 1.015s
found 0 vulnerabilities
[rootz (12)] [letlziml@premium88 rootz]$ npm install express
ln: creating symbolic link `/home/letlziml/nodevenv/rootz/12/lib/package.json': No such file or directory
npm WARN saveError ENOENT: no such file or directory, open '/home/letlziml/nodevenv/rootz/12/lib/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/home/letlziml/nodevenv/rootz/12/lib/package.json'
npm WARN lib No description
npm WARN lib No repository field.
npm WARN lib No README data
npm WARN lib No license field.
+ [email protected]
updated 1 package and audited 88 packages in 1.009s
found 0 vulnerabilities
[rootz (12)] [letlziml@premium88 rootz]$ npm install https
ln: creating symbolic link `/home/letlziml/nodevenv/rootz/12/lib/package.json': No such file or directory
npm WARN saveError ENOENT: no such file or directory, open '/home/letlziml/nodevenv/rootz/12/lib/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/home/letlziml/nodevenv/rootz/12/lib/package.json'
npm WARN lib No description
npm WARN lib No repository field.
npm WARN lib No README data
npm WARN lib No license field.
+ [email protected]
added 1 package from 1 contributor and audited 89 packages in 0.977s
found 0 vulnerabilities
[rootz (12)] [letlziml@premium88 rootz]$ npm install https
ln: creating symbolic link `/home/letlziml/nodevenv/rootz/12/lib/package.json': No such file or directory
npm ERR! code EJSONPARSE
npm ERR! file /home/letlziml/nodevenv/rootz/12/lib/package.json
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected end of JSON input while parsing near ''
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/letlziml/.npm/_logs/2020-10-09T11_07_13_947Z-debug.log
[rootz (12)] [letlziml@premium88 rootz]$ npm install wss
ln: creating symbolic link `/home/letlziml/nodevenv/rootz/12/lib/package.json': No such file or directory
npm ERR! code EJSONPARSE
npm ERR! file /home/letlziml/nodevenv/rootz/12/lib/package.json
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected end of JSON input while parsing near ''
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/letlziml/.npm/_logs/2020-10-09T11_09_42_615Z-debug.log
[rootz (12)] [letlziml@premium88 rootz]$ npm install 'wss'
ln: creating symbolic link `/home/letlziml/nodevenv/rootz/12/lib/package.json': No such file or directory
npm ERR! code EJSONPARSE
npm ERR! file /home/letlziml/nodevenv/rootz/12/lib/package.json
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected end of JSON input while parsing near ''
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/letlziml/.npm/_logs/2020-10-09T11_10_04_988Z-debug.log
[rootz (12)] [letlziml@premium88 rootz]$ npm install fs
ln: creating symbolic link `/home/letlziml/nodevenv/rootz/12/lib/package.json': No such file or directory
npm ERR! code EJSONPARSE
npm ERR! file /home/letlziml/nodevenv/rootz/12/lib/package.json
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected end of JSON input while parsing near ''
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/letlziml/.npm/_logs/2020-10-09T11_12_22_034Z-debug.log
[rootz (12)] [letlziml@premium88 rootz]$ source /home/letlziml/nodevenv/rootz/12/bin/activate && cd /home/letlziml/rootz
[rootz (12)] [letlziml@premium88 rootz]$ netsh /?
bash: netsh: command not found
[rootz (12)] [letlziml@premium88 rootz]$ /?
bash: /?: No such file or directory
[rootz (12)] [letlziml@premium88 rootz]$
it said that it cannot find the file package.json or could not read/parse this file. So I created a blank file to see if it would write data too it or populate it with the necessary info, now when i run npm on any module its no longer giving warnings and just throws an error… Does anybody know how to fix this?
pretty sure that both https & express installed properly as when I look in the modules folder they are now in there, when they were not before. However when i try to create a https server, the webpage is still throwing an error.
Have watched quite a few node tutorials on youtube, but this part is still confusing me.
ps. 1) What does ENOENT mean?
2) How do you auto populate the package.json file with all the correct info?
2
Answers
To install packages locally you need to be within a project. The project folder simply needs a package.json
Running
npm init
will guide you through the creation of a node project. Check https://docs.npmjs.com/cli/init for further clarification. When installing packages to a projectnpm install --save <package name>
will update package json and include the dependency to it.Additionally there are also global packages which can be installed via
npm install -g <package name>
. Those will be available globally. These are typically CLI tools running on nodejs.I would recommend running npm init and trying out a simple hello world project to get going.
ENOENT: Why does ENOENT mean "No such file or directory"?
I just succeeded in deploying my second node.js app to a remote server (Irish web servers). For me in cPanel in the main page there was an "Install Node.js" icon. Following the docs I opened it. Having transferred all files using ftp to the server except the
node_modules
folder, I clicked on the icon and created a node.js app following the instructions in the cPanel docs. Then I clicked on the button that saidRun npm install
. This does the same as$ npm install locally
. It looks in the package.json file and installs any packages listed in dependencies, but it installs them in a folder which is a branch of the server’s root dir (not your websites’s) and seems to be inaccessible, to me at least. Even accessing the server using my terminal using ssh$ ssh username@serverIPaddress
although it allowed me to$ npm install express
I doubt if that would have any effect on my project. One of the errors you got aboveFailed to parse json
I got that when I left out a comma in the json file after editing it. When you run$ npm init
locally it creates a perfectpackage.json
file. If you upload that to your website root dir it might fix that error. Good luck!