Learning Node.js 001 – Starting an App

Once a shell of an app is created, it can be started with the command node app.js  (assuming that the app’s main file is app.js. Other common names are server.js and index.js)

The alternative way to start an app is with the command npm start. By default npm start will fill look for a start property in the package.json file. For example:

"scripts": {
    "start": "node app.js"

If the package.json file doesn’t contain a start property, npm start will default to node server.js.  Note: this will only work if your main file is called server.js.

The first time I tried using npm start, I got the following error:

npm ERR! Invalid name: "Vert Tracker"
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/kevin/.npm/_logs/2018-05-23T22_09_11_616Z-debug.log

Digging around I found that the name property of the package.json file cannot contain spaces or capital letters. After I changed the name to “vert-tracker”, npm start worked. There are other tips on the package.json npm page.

Leave a Reply

Your email address will not be published. Required fields are marked *