Node.js local-web-server: can't find module ws (installed globally)

9.1k Views Asked by At

I want to start a simple local webserver for local development on Windows 7. For this I installed node.js and then ran:

npm install -g local-web-server

Next I went to the folder D:\[path_to_webcontent] containing the index.html, started a cmd-prompt from that folder and ran:

node ws

and get the error:

module.js:338

throw err;

^ Error: Cannot find module 'D:[path_to_webcontent]\ws'

Why can't node find the globally installed webserver? The module "local-web-server" is located at C:\Users\<user>\AppData\Roaming\npm\node_modules.

2

There are 2 best solutions below

0
tokeryberg On BEST ANSWER

Instead of node ws you just type wsin the cmd-prompt.

From the documentation on npm (https://www.npmjs.com/package/local-web-server):

$ npm install -g local-web-server
$ ws

When you write node ws node is looking to run a module called ws. When you want to use a globally installed package you just need to use the package's name in the cmd-prompt.

1
Reza Akraminejad On

If you used referencing module like this and nodejs can't find module path, try:

C:\Users\{your user name}\AppData\Roaming\npm\node_modules

and set the full path in require path or copy ws module folder inside your project folder

var ws= require('ws')

also you can use ../ before module to go one folder up. (relative path)

(remember to mark as answered and vote up ;) if you got the answer)