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
To run this file, you should open up your terminal again and navigate to the directory in which you placed index. js. Once you successfully navigated yourself to the right spot, run your file using the node index. js command.
main. The main field is a module ID that is the primary entry point to your program. That is, if your package is named foo , and a user installs it, and then does require("foo") , then your main module's exports object will be returned. This should be a module relative to the root of your package folder.
To execute your Script, use the 'npm run <NAME-OF-YOUR-SCRIPT>' command.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With