How is an HTTP POST request made in node.js?

request is now deprecated. It is recommended you use an alternative In no particular order and dreadfully incomplete: native HTTP/S, const https = require(‘https’); node-fetch axios got superagent bent make-fetch-happen unfetch tiny-json-http needle urllib Stats comparision Some code examples Original answer: This gets a lot easier if you use the request library. var request = … Read more

Node.js + Nginx – What now?

Nginx works as a front end server, which in this case proxies the requests to a node.js server. Therefore you need to setup an Nginx config file for node. This is what I have done in my Ubuntu box: Create the file yourdomain.example at /etc/nginx/sites-available/: vim /etc/nginx/sites-available/yourdomain.example In it you should have something like: # … Read more

How can I do Base64 encoding in Node.js?

Buffers can be used for taking a string or piece of data and doing Base64 encoding of the result. For example: > console.log(Buffer.from(“Hello World”).toString(‘base64’)); SGVsbG8gV29ybGQ= > console.log(Buffer.from(“SGVsbG8gV29ybGQ=”, ‘base64’).toString(‘ascii’)) Hello World Buffers are a global object, so no require is needed. Buffers created with strings can take an optional encoding parameter to specify what encoding the … Read more

How do I get the path to the current script with Node.js?

I found it after looking through the documentation again. What I was looking for were the __filename and __dirname module-level variables. __filename is the file name of the current module. This is the resolved absolute path of the current module file. (ex:/home/kyle/some/dir/file.js) __dirname is the directory name of the current module. (ex:/home/kyle/some/dir)

How can I uninstall npm modules in Node.js?

The command is simply npm uninstall <name> The Node.js documents https://npmjs.org/doc/ have all the commands that you need to know with npm. A local install will be in the node_modules/ directory of your application. This won’t affect the application if a module remains there with no references to it. If you’re removing a global package, … Read more

tech