What is my syntax error using relative path instead of absolute in json file?


There is a folder "server" in it is installed http server and package.json .
It also contains the webdir folder with a web page.

I can go to the "webdir" folder via the console and type the node [абсолютный путь до файла, запускающего сервер: (.....)/node_modules/http-server/bin/http-server] command node [абсолютный путь до файла, запускающего сервер: (.....)/node_modules/http-server/bin/http-server] .

I want another user, after downloading my mpn package from Saito and the server, to immediately type mpn start and he would activate the server and open a web page at localhost:8080 .

I was able to start the server using the npm start command (after opening the "webdir" folder through the console) by adding it to package.json and using the absolute path to the http-server.

 "scripts": { "start": "node (.....)/server/node_modules/http-server/bin/http-server" }, 

It works.

But the path will be different for different users. I tried to specify a relative path, since I have to activate the server from the "webdir" folder, the path looks like this: ../node_modules/http-server/bin/http-server I get an error.

enter image description here

Why is this happening and how to fix it?

  • So is there a module for this path? maybe just the wrong relative path? - Grundy
  • @Grundy path - copied absolute path, but instead of the first part, up to the folder "server" - ../ - then comes the name of the folder, which is on the same level with the webdir folder, etc. - Rumata
  • I meant the way he swears: cannot find module '(...)/node_modules/http-server/bin/http-server' match the absolute path? - Grundy
  • @Grundy Yes, the path is the same. Did I make a syntax error? ../ to exit to the level above (from the webdir folder), further the path is the same. - Rumata
  • Try this "start": "node http-server" without specifying the path. When using the scripts section, the node automatically scans the project bin folder - pitersky

0