I'm trying to run my node.js server locally. Before, I had done it in Replit, where it makes it easy to set up. I'm a little stuck though.
I have a folder for my project, with a server.js file, package.json, package-lock.json, and a public folder containing index.html. I'm using socket.io, express, http, and cookie-parser. They are all in a node_modules folder.
In server.js, I use
const { Server } = require('socket.io');
This worked in Replit.
The package.json file contains these dependencies:
"dependencies": {
"body-parser": "^1.19.1",
"cookie": "^0.4.1",
"cookie-parser": "^1.4.6",
"express": "^4.17.2",
"socket.io": "^4.4.1"
}
I use the command
.load correct\path\to\server.js
in the Node.js command line.
When I run server.js in Node.js, I get this message:
Cannot find module 'socket.io'
Help?
CodePudding user response:
Sounds like you need to install the dependencies, try executing npm install, after that you use "node" to run your code.
For example: node correct\path\to\server.js
CodePudding user response:
You need to install all the dependent modules through npm install, In your case, you need to install
node-SQL server
npm install node-sqlserver
Generally your source code will be having a
package.json. This file specifies all the dependent modules required to run the application, but here this file is missing.
