Search code examples
node.jsjsonlinuxnpmsudo

error when i type 'npm start' to conect my website with localhost


I'm trying to start a web page, but when i type npm start in the terminal(in folders proyect) shows me an error.

npm ERR! syscall open
npm ERR! path /home/dmarin/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/home/dmarin/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/dmarin/.npm/_logs/2020-02-20T16_05_39_782Z-debug.log

am connected to a mysql database in localhost , using php admin with apache.Your help will be more than great full.


Solution

  • If you want to use npm to start your server, which then will serve web pages, then you will need to do npm init, it will create pacakage.json

    It will look something like this:

    
      > npm init --yes
      Wrote to /home/ag_dubs/my_package/package.json:
    
      {
        "name": "my_package",
        "description": "",
        "version": "1.0.0",
        "main": "index.js",
        "scripts": {
          "test": "echo \"Error: no test specified\" && exit 1"
        },
        "repository": {
          "type": "git",
          "url": "https://github.com/ashleygwilliams/my_package.git"
        },
        "keywords": [],
        "author": "",
        "license": "ISC",
        "bugs": {
          "url": "https://github.com/ashleygwilliams/my_package/issues"
        },
        "homepage": "https://github.com/ashleygwilliams/my_package"
      }
    

    npm start looks for pacakage.json file or pacakage-lock.json file. and will launch the file that you mention in pacakage.json.

    In the above file, it will look for:

    "main": "index.js"

    so all you need to do is replace index.js with the webpage you want.