Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Demonstrates writing text to a local file using Node's fs module in NW.js.
// package.json
{
"name": "file-writer",
"main": "index.html",
"window": { "title": "File Writer", "width": 600, "height": 400 }
}
// index.html
<!DOCTYPE html>
<html>
<body>
<h1>Write File</h1>
<textarea id='text' rows='6' cols='40'></textarea><br>
<button id='saveBtn'>Save</button>
<script>
const fs = require('fs');
const path = require('path');
document.getElementById('saveBtn').onclick = () => {
const text = document.getElementById('text').value;
fs.writeFile(path.join(process.cwd(), 'output.txt'), text, err => alert(err || 'File saved!'));
};
</script>
</body>
</html>NW.js (previously known as Node-Webkit) is an open-source framework for building desktop applications using web technologies (HTML, CSS, JavaScript) with full access to Node.js APIs.
Origin & Creator
Developed by Intel’s Open Source Technology Center in 2011 (originally as Node-Webkit) to enable web developers to build desktop applications easily.
Industrial Note
NW.js is popular for desktop apps that need a web-like interface, rapid prototyping, or access to Node.js modules in a desktop environment.