Sync:

var fs = require('fs');
var obj = JSON.parse(fs.readFileSync('file', 'utf8'));

Async:

var fs = require('fs');
var obj;
fs.readFile('file', 'utf8', function (err, data) {
  if (err) throw err;
  obj = JSON.parse(data);
});
Answer from mihai on Stack Overflow
๐ŸŒ
HeyNode
heynode.com โ€บ tutorial โ€บ readwrite-json-files-nodejs
Read/Write JSON Files with Node.js | HeyNode
If you want to learn more, you can read up on what JSON actually is, and find out more about synchronous vs asynchronous code. Learn about using Node.js Streams to read really large files. Walk through this example with a co-worker. Are all the concepts clear to you? Do you need to review anything? File System (Node v12.5.0 Documentation) (nodejs...
Discussions

How do I read a JSON file into (server) memory?
I am doing some experimentation with Node.js and would like to read a JSON object, either from a text file or a .js file (which is better??) into memory so that I can access that object quickly fro... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to parse big json files
By the looks of it you need the whole data structure in the memory. You need to identify what is you performance bottleneck. Is it reading the file or is it JSON.parse or is it your logic? I would start from there. If your validation logic is run only on "edges" and "nodes" then parse only those. More on reddit.com
๐ŸŒ r/node
6
2
April 14, 2021
Google Cloud Function- Reading JSON file inputs in Node.JS
https://cloud.google.com/functions/docs/samples/functions-http-form-data#functions_http_form_data-nodejs More on reddit.com
๐ŸŒ r/googlecloud
3
2
July 11, 2022
Need some help to create, store and access JSON files for my webapp which will be later ported to electron
https://www.electronjs.org/docs/latest/api/synopsis You're writing an Electron app - at this point, you have to develop it in Electron, not as a browser app. Unless you want to implement useless abstractions that'll be thrown away soon, that is. More on reddit.com
๐ŸŒ r/node
2
2
June 24, 2023
๐ŸŒ
TecAdmin
tecadmin.net โ€บ parse-json-nodejs
How To Parse JSON in Node.js - TecAdmin
April 26, 2025 - This tutorial will help you to read JSON file using Node.js uses readFile and readFileSync functions of the jsonfile module.
๐ŸŒ
Futurestud.io
futurestud.io โ€บ tutorials โ€บ node-js-read-a-json-file
Node.js โ€” Read a JSON File
Node.js provides the fs module to read files from the local hard disk. Use the Fs.readFile to read the content of a given file. Related to a JSON file, youโ€™ll then have the JSON content as a string.
๐ŸŒ
LogRocket
blog.logrocket.com โ€บ home โ€บ reading and writing json files in node.js: a complete tutorial
Reading and writing JSON files in Node.js: A complete tutorial - LogRocket Blog
November 1, 2024 - In the Node runtime environment, you can use the built-in require function and fs modules to load or read JSON files. Because the require function is available for each module, you donโ€™t need to require it.
๐ŸŒ
Better Stack
betterstack.com โ€บ community โ€บ questions โ€บ using-node-how-to-read-json
Using node.js, How Do I Read a Json File into (Server) Memory? | Better Stack Community
const fs = require('fs'); // Specify the path to your JSON file const filePath = 'path/to/your/file.json'; // Read the JSON file fs.readFile(filePath, 'utf8', (err, data) => { if (err) { console.error('Error reading JSON file:', err); return; } // Parse the JSON data try { const jsonData = JSON.parse(data); // Now you have the JSON data in memory console.log('JSON Data:', jsonData); } catch (parseError) { console.error('Error parsing JSON:', parseError); } });
Find elsewhere
๐ŸŒ
Geshan
geshan.com.np โ€บ blog โ€บ 2024 โ€บ 10 โ€บ nodejs-read-json-file
How to Read a JSON File Using Node.js
October 30, 2024 - Learn how to read a JSON file using Node.js. This post covers reading a JSON file synchronously and asynchronously using the fs module and fs-extra NPM package.
๐ŸŒ
DEV Community
dev.to โ€บ tejesh โ€บ nodejs-read-json-file-using-require-vs-fs-module-4f94
NodeJS require() vs fs.readFileSync to read JSON files - DEV Community
May 14, 2020 - you can read json files either using require('filename.json') or fs.readFileSync('filename.json') If the JSON file is static, require() is better because require() caches the file.
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ bytes โ€บ how-to-import-a-json-file-in-javascript-node-js
How to Import a JSON File in JavaScript/Node.js
September 18, 2023 - Importing a JSON file in Node.js is very easy to do since JSON is a native type to JS. You can use the built-in fs (file system) module to read the file, and then parse it into a JavaScript object using JSON.parse().
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ node.js โ€บ how-to-read-and-write-json-file-using-node-js
How to read and write JSON file using Node ? - GeeksforGeeks
July 12, 2025 - A straightforward way to read a JSON file in a Node JS file is by using the `require()` method to include it.
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_json.asp
W3Schools.com
JSON is used to send, receive and store data. ... Code for reading and generating JSON data can be written in any programming language.
๐ŸŒ
CodeSignal
codesignal.com โ€บ learn โ€บ courses โ€บ hierarchical-and-structured-data-formats-in-ts โ€บ lessons โ€บ parsing-json-files-in-typescript-using-nodejs
Parsing JSON Files in TypeScript Using Node.js
We'll use import to bring in the fs module and read from the file. TypeScript allows us to explicitly declare variable types, enhancing readability and reducing mistakes. Here, filePath is the path to the JSON file with a declared type of string.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-read-and-write-files-with-nodejs
How to Read and Write Files with Node.js
August 19, 2024 - It's an asynchronous JavaScript function that takes a filename as input and aims to return the parsed JSON contents of that file. Inside a try block, we attempt to read the file using fs.readFile in Node with the specified filename and "utf8" encoding.
๐ŸŒ
OneUptime
oneuptime.com โ€บ home โ€บ blog โ€บ how to read json files in node.js
How to Read JSON Files in Node.js
January 22, 2026 - const fs = require('fs/promises'); async function readJSON(filepath) { const data = await fs.readFile(filepath, 'utf8'); return JSON.parse(data); } // Usage async function main() { try { const config = await readJSON('./config.json'); ...
๐ŸŒ
Codebitshub
codebitshub.com โ€บ home โ€บ reading json file in javascript + working with json
Reading JSON File In Javascript + Working With JSON - codebitshub.com
February 5, 2022 - On the other hand, we can convert an Object to a JSON string using the JSON.stringify method. Letโ€™s summarize what you learned in this tutorial ยท You can use the fetch API in order to read a file in javascript
๐ŸŒ
Node.js
nodejs.org โ€บ en โ€บ learn โ€บ manipulating-files โ€บ reading-files-with-nodejs
Node.js โ€” Reading files with Node.js
const fs = require('node:fs/promises'); async function example() { try { const data = await fs.readFile('/Users/joe/test.txt', { encoding: 'utf8' }); console.log(data); } catch (err) { console.error(err); } } example();
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ API โ€บ Fetch_API โ€บ Using_Fetch
Using the Fetch API - Web APIs | MDN
Note that just like response bodies, request bodies are streams, and making the request reads the stream, so if a request contains a body, you can't make it twice: ... const request = new Request("https://example.org/post", { method: "POST", body: JSON.stringify({ username: "example" }), }); const response1 = await fetch(request); console.log(response1.status); // Will throw: "Body has already been consumed." const response2 = await fetch(request); console.log(response2.status);
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ nodemon
nodemon - npm
3 weeks ago - If you have a package.json file for your app, you can omit the main script entirely and nodemon will read the package.json for the main property and use that value as the app (ref).
      ยป npm install nodemon
    
Published ย  Feb 20, 2026
Version ย  3.1.14
Author ย  Remy Sharp
Homepage ย  https://nodemon.io
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ reading-and-writing-json-files-with-node-js
Reading and Writing JSON Files with Node.js
July 8, 2024 - As you can see, the JSON from our file was successfully loaded in to the student object. Another way you can read a JSON file in Node.js is using the readFile function. Unlike readFileSync function, the readFile function reads file data in an asynchronous manner.