How to process POST data in Node.js?

You can use the querystring module: var qs = require(‘querystring’); function (request, response) { if (request.method == ‘POST’) { var body = ”; request.on(‘data’, function (data) { body += data; // Too much POST data, kill the connection! // 1e6 === 1 * Math.pow(10, 6) === 1 * 1000000 ~~~ 1MB if (body.length > 1e6) … Read more

Do I commit the package-lock.json file created by npm 5?

Yes, package-lock.json is intended to be checked into source control. If you’re using npm 5+, you may see this notice on the command line: created a lockfile as package-lock.json. You should commit this file. According to npm help package-lock.json: package-lock.json is automatically generated for any operations where npm modifies either the node_modules tree, or package.json. … Read more

How to exit in Node.js

Call the global process object’s exit method: process.exit() From the docs: process.exit([exitcode]) Ends the process with the specified code. If omitted, exit with a ‘success’ code 0. To exit with a ‘failure’ code: process.exit(1); The shell that executed node should see the exit code as 1.

What’s the difference between dependencies, devDependencies and peerDependencies in npm package.json file?

Summary of important behavior differences: dependencies are installed on both: npm install from a directory that contains package.json npm install $package on any other directory devDependencies are: also installed on npm install on a directory that contains package.json, unless you pass the –production flag (go upvote Gayan Charith’s answer), or if the NODE_ENV=production environment variable … Read more