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

4

1 Answer

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like