
Package.json have a special section called scripts. All your packages will be installed instantly. Why? Because all packages are stored in package.json file and after you open your project in a new computer or if you pull the repository from GitHub all you will need to do is install your packages by run npm i in terminal. There will be created a new block in your package.json file called devDependencies(or updated).Īnd you can see a new folder in your project called node_modules. You have to commit it in your GitHub repository. If you already have dependencies in your project the package-lock.json file will be updated. This file contains version history of our dependencies. Package-lock.json will be formatted in your project directory. You can type -ED too.Īfter we installed a first package in our project we can see some events: For example, -D is the same that -save-dev or -E the same that -save-exact Some keys have a short way, one hyphen and initial letter. It’s okay, but if several developer will be working on your project, they in 90% will have a different version of packages. That means “every version from and higher”. If you will forget this key your package will be install with ^ sign. save-exact key is saying to install exact version of the package (usually more newer). It’s no problem but there is a logical split:ĭevDependencies packages is need it for development, dependencies packages is need it for app working. If you will forget this key your package will be installed in dependencies section. save-dev key will install the package in devDependencies section in a package.json file. The are need it to clarify how to install the package.

save-dev and -save-exact are the specifying commands. The most terminal commands have additional settings. The following example demonstrates how to serve JSON response from the Node.js web server.Enter fullscreen mode Exit fullscreen mode It will display "Invalid Request" for all requests other than the above URLs.

The same way, point your browser to and see the following result. To test it, you can use the command-line program curl, which most Mac and Linux machines have pre-installed.Ĭurl -i You should see the following response.įor Windows users, point your browser to and see the following result. Node.js web server at port 5000 is running. Now, run the above web server as shown below. Finally, Node.js web server sends the response using end() method. To send a response, first it sets the response header using writeHead() method and then writes a string as a response body using write() method. In the above example, req.url is used to check the url of the current request and based on that it sends the response.
