I am very new to node.js and am following this tutorial
When I get to step 5, after completing step 1-4 successfully, and run the npm install command I get these errors.
http://i.stack.imgur.com/LPN49.png
Also when I run npm start command I get these errors in image 2
http://i.stack.imgur.com/TrOJz.png
Please help me rectify these errors.
I originally answered this question on Quora -- including an explanation about why the SO community frowns on this type of question -- but here's the technical portion if anyone comes to this question for a more general answer:
npm install goes through the list of dependencies in your package.json file, fetches each one from NPM, then installs it locally for you. If there was an error with that process then you will be missing one or more dependencies -- if you try to run node /path/to/node/server/file then Node and Express will start looking for dependencies that may not be there because your npm install errored out.
Additionally, you can only use npm start if the package.json file has a scripts property that tells node what start script to use. If it's not there, it falls back to node server.js, which won't start your server if it's called something other than server.js. (For more information: node.js express npm start)
You should try to confirm whether your package.json is actually at the file path on the first "ERR!" line after you ran npm install. I'm guessing it didn't find the file so it couldn't install dependencies, and then you're getting an error from npm start because you didn't install Express's body-parser dependency, which prevented it from starting your server.
Related
Hello, World!
I am having trouble getting NPM working.
First, I installed node.js from https://nodejs.org/en/download/ (the 64-bit .msi, on Windows 10, Version 10.0.18362 Build 18362). Node -v is 12.16.3.
Using Powershell, I navigated to the nodejs directory created in the install. Then I attempted npm install, which ultimately drew a series of errors beginning with "ENOENT: no such file or directory, open '...\nodejs\package.json' ".
The nodejs directory contains a file called "package-lock.json", but no "package.json".
Renaming the "-lock" file did not fix the error.
I've read on this site that Node came with NPM pre-installed. I can run npm -v without a problem ("6.14.4" returned) but trying npm start gives me the same error as npm install (cannot find package.json).
I have uninstalled Node & reinstalled twice, same problem.
Thoughts?
You should create a package.json file for every project using npm libraries, whether or not you are going to publish your code anywhere.
The easiest way is to run npm init and answer the questions, then npm will create the package.json file.
(Or take a look at the docs for other ways to run init, like npm init -y to just generate a plain package.json that you can manually edit.)
BTW, package-lock.json is a different kind of file that's generated to say which versions of each transitive dependency were installed. It doesn't have the same format as package.json; don't mix them.
I'm trying to install socket.io on localhost.
I installed nodejs like this:
1. npm install pm2 -g
2. npm install socket.io
3. pm2 start C:\xampp\htdocs\server\app.js
Yesterday It was successful and I worked on my project.
But today when I start same file again, I get an error like this;
https://i.imgur.com/V89qWhP.png
And I open logs, the message showed:
https://i.imgur.com/pLj5dgx.png
I'm trying to solve this problem for hours.
I even tried to reinstall Node at least 4-5 times.
Still same problem, please help.
At first glance I would recommend you to run a npm install before starting your app.
We need additional information about your require statement, your package.json dependencies and the full error message.
I have installed Node.js and at first when I wrote an npm command like npm install -g <> or npm start it worked, but now it doesn't. I removed and installed node again and am still facing the same problem:
~$ npm install
~$
No action is made and the terminal returns back to normal.
npm install looks for a package.json file in your current directory. It installs all the dependencies listed in the package.json. Similarly npm start looks in the package.json scripts to see what command it should really run. If it doesn't work now, you are probably in the wrong directory. If you are in the correct directory, can you provide more information like the exact error message you are getting?
I have an application on with a node server and I would like to do something like :
npm start
and node dependencies will install and bower dependencies will install, after that a browser window could open.
Can I do this without gulp/grunt? If I need gulp/grunt I don't mind.
You must issue
npm install
before you call the command npm start, because when the scripts start to run they need the dependencies already installed.
And to start a server and open it in a browser, it's well explained here:
How to Use npm as a Build Tool
(Look at the last example of the article)
I am very new to node.js so please pardon my ignorance on a simple question. I am adding dependencies to package.json for a node.js application and am wondering if it's possible to specify command line arguments that would normally be passed to npm install. For example, when installing the mongodb package from the command line, you might need to pass an option:
npm install mongodb --mongodb:native
Is their a way with the package.json syntax to specify that a package should be installed with command line options?
It's not perfect, but I have been able to get around this problem by adding an explicit npm install into the preinstall script of my package.json file. In this way, the mongodb package is added as a binary before npm gets a chance to do it incorrectly. Hope this helps
"scripts": {
"preinstall" : "npm install mongodb '--mongodb:native'"
}