Keri Marr
Keri Marr

Reputation: 477

How to start main index.js from my package.json file

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

Upvotes: 32

Views: 69609

Answers (1)

Javapocalypse
Javapocalypse

Reputation: 2363

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

Upvotes: 40

Related Questions