home.


Tagged: nodejs


NodeJS: Write javascript to JSON file

If you want to write your javascript object to a json file, it’s easy enough:

fs.writeFileSync('thefilename.json', JSON.stringify(your_object))

This will synchronously write your file, too, unlike the other variant which calls a callback when it’s finished.

nodejs json

Simple SQLite3 and NodeJS interactions

Firstly install sqlite3, npm -g install sqlite3 then:

const sqlite3 = require('sqlite3');
var yourdb = new sqlite3.Database('yourdb.sqlite3');
yourdb.all("select * from yourtable", [], function(e, row) { console.log(row) })
nodejs sqlite

NodeJS: Increase allocated memory

You may find NodeJS crashes due to lack of memory. You can increase it as follows (to 6gb):

node --max-old-space-size=6144

nodejs

Page 1 of 1