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)

Using Node.js require vs. ES6 import/export

Update Since Node v12 (April 2019), support for ES modules is enabled by default, and since Node v15 (October 2020) it’s stable (see here). Files including node modules must either end in .mjs or the nearest package.json file must contain “type”: “module”. The Node documentation has a ton more information, also about interop between CommonJS … Read more

How do I get started with Node.js [closed]

You can follow these tutorials to get started: Tutorials NodeSchool.io interactive lessons The Art of Node (an introduction to Node.js) Hello World Hello World Web Server (paid) Node.js guide Build a blog with Node.js, express and MongoDB Node.js for Beginners Learn Node.js Completely and with Confidence Node JS Processing Model – Single Threaded Model with … Read more

How can I get the full object in Node.js’s console.log(), rather than ‘[Object]’?

You need to use util.inspect(): const util = require(‘util’) console.log(util.inspect(myObject, {showHidden: false, depth: null, colors: true})) // alternative shortcut console.log(util.inspect(myObject, false, null, true /* enable colors */)) Outputs { a: ‘a’, b: { c: ‘c’, d: { e: ‘e’, f: { g: ‘g’, h: { i: ‘i’ } } } } }