Tuj learning Node.js: package.json

Installing the mysql package

We npm installed mysql package in our project folder and used the selective sync trick to prevent Dropbox from syncing the node_modules folder. Saved just 865KB...

Then we checked the documentation of this package. What's the matter with question marks? Why does it replace ? with stuff even when ? is protected by quotes? This looks weird, so we need to be careful when such a use case arises when we do not want ? to be replaced.

First nodejs app

Then we produced our Hello World nodejs app!!! Sorry, not using the mysql package yet.

//hw.js
console.log('Hello World!');

Run it with node hw. [Not sure if it is better to add the js extension.]

To use the irksome npm to manage the project, one should have a package.json file in the project folder that contains info about the project such as dependencies, how to run it and the usual: title, version, author, license...

npm init can help one build a package.json file. The how to run part seems to be covered by the scripts value in the file. In addition, it also manages how to install etc. If we really want npm to run our hello world app, we can put a shell script in the value for the start key in the scripts or put it in that for the test key? The documentation seems to suggest that start is for server type of apps. Our package.json file:

{
    "name": "hw",
    "version": "1.0.0",
    "description": "nyan",
    "main": "index.js",
    "scripts": {
        "test": "node hw",
        "start": "node hw"
    },
    "author": "tuj",
    "license": "ISC"
}

We are simply putting what we told bash in the test and start fields. Then we run our hello world cutey with npm test or npm start.

Documentations:

https://docs.npmjs.com/files/package.json
https://docs.npmjs.com/misc/scripts