25

I have installed node.js and I have created with npm init -f my very first module.

In created package.json file I see "main": "index.js", which should be starting point of my application. So in same folder I have created this file and I have putted there console.log('test')

The problem is that I don't know how to run it without declaring "scripts": { "start": "node index.js" }

Should I always have scripts section. Because I'm missing why there is entry point of application when I have to use scripts section anyway.

Thanks

Keri Marr
  • 407
  • 2
  • 6
  • 13
  • 1
    Possible duplicate of [Node.js package.json main parameter](https://stackoverflow.com/questions/22512992/node-js-package-json-main-parameter) – kgangadhar Dec 21 '18 at 20:16
  • Second answer from your link gave me the answer – Keri Marr Dec 21 '18 at 22:21
  • Please go through the existing posts solutions related to the problems you are facing before posting the question, it'll help stackoverflow to avoid duplicates of the same kind. – kgangadhar Dec 21 '18 at 22:26
  • 1
    I did that, I have read documentation from node.js, also checked several topics here in stackoverflow, but I was confused as beginner and I didn't find relevant topic which explain it like I saw it from your link. – Keri Marr Dec 21 '18 at 22:45

1 Answers1

31

Please do read the Getting Started Guide | Node.js. You can start the web server by typing

node index.js

if you have the index.js file specified in package.json as follows

{
    ....
    "scripts": {
        "start": "node index.js"
    }
    ....
}

You can also run the server by the following command

npm start

You can read about the difference between npm start and node index.js here

Javapocalypse
  • 2,223
  • 17
  • 23