NEQTO Docs
  • Languages iconEnglish
    • 日本語
  • Docs
  • API
  • FAQ

›neqto.js

Getting Started

  • NEQTO Hello World!
  • Tutorial Step 1. NEQTO Console Setting
  • Tutorial Step 2. Device Settings & Launching Service (NEQTO Bridge)
  • Tutorial Step 2. Device Settings & Launching Service (STM32 Discovery)
  • Tutorial Step 2. Device Settings & Launching Service (SPRESENSE)
  • Tutorial Step 3. Application development using scripts

NEQTO

  • NEQTO Account Registration
  • Sub-accounts
  • API Usage
  • NEQTO Engine Firmware List
  • Support Guidelines
  • For safe and secure use of the NEQTO products
  • Vulnerability Disclosure Policy

NEQTO Console

  • Introduction
  • Fundamentals
  • Administrative Actions
  • Device Management
  • Linux-based Device Management
  • Batch Registration
  • Scripts
  • Actions and Contacts
  • View Data from the Console
  • NEQTO Apps

    • About NEQTO Apps
    • NEQTO Infinitypool
    • NEQTO Insights
    • NEQTO Custodia
    • NEQTO Flow
  • Machine Driver
  • Recommended Browsers
  • Billing Information

SPRESENSE

    Hardware Specifications

    • 01. About Spresense

    Software Specifications

    • 01. Operational Flow
    • 02. Initial Installation
    • 03. Spresense Wi-Fi Initial Setup
    • 04. Spresense LTE-M Initial Setup
    • 05. Debug Log Acquisition
    • 06. System LED Indications
    • 07. Event Messages
    • 08. Updating Firmware

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. Sleep
    • 10. RTC
    • 11. GPIO
    • 12. UART
    • 13. SPI
    • 14. I2C
    • 15. ADC
    • 16. GNSS
    • 17. Camera
    • 18. Utils
    • 19. nqSpresense
    • 20. nqService
    • 21. nqMqtt
    • 22. nqFOTA
    • 23. nqWiFi
    • 24. nqLte

STM32 Discovery

    Hardware Specifications

    • 01. About STM32 Discovery Kit (B-L4S5I-IOT01A)

    Software Specifications

    • 01. Operational Flow
    • 02. Initial Installation
    • 03. STM32 Discovery Wi-Fi Initial Setup
    • 04. Debug Log Acquisition
    • 05. System LED Indications
    • 06. Event Messages
    • 07. Updating Firmware

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. Sleep
    • 10. RTC
    • 11. UserSW
    • 12. GPIO
    • 13. UART
    • 14. SPI
    • 15. I2C
    • 16. ADC
    • 18. Utils
    • 19. nqDiscovery
    • 20. nqService
    • 21. nqMqtt
    • 22. nqFOTA
    • 23. nqWiFi

NEQTO Bridge

    Hardware Specifications

    • 01. NEQTO Bridge Module
    • 02. NEQTO Bridge Wi-Fi Module
    • 03. NEQTO Bridge LTE-1 Module
    • 04. NEQTO Bridge LTE-M/NB Module
    • 05. NEQTO Bridge IO Board
    • 06. NEQTO Bridge Digital IO Board
    • 07. NEQTO Bridge Connector Board

    Software Specifications

    • 01. Operational Flow
    • 02. NEQTO Bridge Wi-Fi Module Initial Setup
    • 03. NEQTO Bridge LTE Module Initial Setup
    • 04. Debug Log Acquisition
    • 05. System LED Indications
    • 06. Event Messages
    • 07. Updating Firmware

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. Sleep
    • 10. RTC
    • 11. UserSW
    • 12. GPIO
    • 13. UART
    • 14. SPI
    • 15. I2C
    • 16. ADC
    • 17. BLE
    • 18. Utils
    • 19. nqBridge
    • 20. nqService
    • 21. nqMqtt
    • 22. nqFOTA
    • 23. nqWiFi
    • 24. nqLte
    • 25. nqLAN
    • 26. nqEx

Linux-based device

    Software Specifications

    • 01. System Requirements
    • 02. Installation
    • 03. Software Configurations
    • 04. Operational Flow
    • 05. Debug Log Acquisition
    • 06. Event Messages
    • 07. Updating Software

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. RTC
    • 10. UNIXSocket
    • 11. FileSystem
    • 12. SubProcess
    • 13. SubTask
    • 14. Queue
    • 15. Utils
    • 16. nqLinux
    • 17. nqService
    • 18. nqMqtt
    • 19. nqFOTA
    • 20. nqLAN

neqto.js Libraries

  • About neqto.js Libraries
  • UART

    • GM65 Barcode Reader
    • SRF Ultrasonic Range Finder - Serial Mode

    I2C

    • HTS221 v2 Temperature and Humidity Sensor
    • LIS2DW12 v2 Accelerometer
    • SRF Ultrasonic Range Finder - I2C Mode
    • [Archive] HTS221 Temperature and Humidity Sensor
    • [Archive] LIS2DW12 Accelerometer

    Utils

    • RTC Alarm Synchronized Scheduler

    Integration

    • AWS S3 v2
    • AWS IoT Core v2
    • Azure IoT v2
    • [Archive] GCP IoT Core
    • [Archive] AWS S3
    • [Archive] AWS IoT Core

neqto.js Snippets

  • About neqto.js Snippets
  • DataDog
  • Dropbox
  • Google Sheets
  • InfluxDB
  • Oracle Cloud Object Storage
  • Salesforce
  • Splunk
  • Niagara
  • [Archive] SAP Cloud Platform Internet of Things

Release Notes

  • NEQTO Console Updates
  • NEQTO Firmware (Bridge Wi-Fi/LTE Module) Releases
  • NEQTO Firmware (STM32 Discovery Wi-Fi) Releases
  • NEQTO Firmware (Spresense Wi-Fi/LTE-M) Releases
  • NEQTO Engine for Linux Releases
  • neqto.js Libraries Releases

11. FileSystem

The fs object is a built-in object that provides access to any file in the file system.

Functional overview:

  • Provides the functions of retrieving information, copying, renaming, deleting, and changing permissions for a file or directory.
  • Provides the function to read/write files by sequential access.
  • Provides the function to read/write files by random access.

Limitations:

  • The number of file resources that can be used is 5. (Version 00.00.04+) (Previous version: 3)



fs Global Object

Methods()/PropertiesSummaryVersionNote
fs.stat()Gets the detailed information of a file or directory.
fs.configure()Changes the configuration of a file or directory.
fs.rename()Renames a file or directory.
fs.remove()Removes a file or directory.
fs.mkdir()Makes a directory.
fs.fcopy()Copies a file.
fs.fopen()Opens a file and creates a file instance.



Details

fs.stat(path)

Gets the detailed information of a file or directory.

NameTypeM/OSummaryNote
pathstringmandatorySpecify a file or directory path.
Ex) /tmp/dir1, /tmp/dir1/test.txt
return{Stat}, null-{Stat} : File information (If the file or directory exists)
null : If file information could not be obtained (If the file or directory does not exist)
If the parameter is abnormal, an exception occurs.

{Stat}

NameTypeSummaryNote
.isFilebooleanWhether it is a file or not
.isDirectorybooleanWhether it is a directory or not
.sizenumberTotal size [Byte]
.blksizenumberPreferred I/O block size [Byte]
.atimenumberTime of last access (unixtime[ms])
.mtimenumberTime of last data modification (unixtime[ms])
.ctimenumberTime of last file status change (unixtime[ms])
.permissionstringPermissions
It will be an octal notation string.
Ex) '0777', '0754'
.uidnumberUser ID of owner
.gidnumberGroup ID of owner
.ownerstringUser name of owner
.groupstringGroup name of owner

fs.configure(path,options)

Changes the configuration of a file or directory.

NameTypeM/OSummaryNote
pathstringmandatorySpecify a file or directory path.
Ex) /tmp/dir1, /tmp/dir1/test.txt
optionsObjectmandatoryOptions
Refer to Options for details.
returnboolean-true : Success
false : Failure
If the parameter is abnormal, an exception occurs.

Options

NameTypeM/OSummaryNote
permissionstringoptionalChange the permissions.
Specify in octal notation string.
Ex) '0777', '0754'
ownernumber, stringoptionalChange the user of owner.
Specify the owner's user ID (type number) or owner's user name (type string). The specified user must have already been created. New registration is not allowed.
groupnumber, stringoptionalChange the group of owner.
Specify the owner's group ID (type number) or the owner's group name (type string). The specified group must have already been created. New registration is not allowed.

fs.rename(oldPath,newPath)

Renames a file or directory.

NameTypeM/OSummaryNote
oldPathstringmandatorySpecify the file or directory path to change from.
Ex) /tmp/dir1, /tmp/dir1/test.txt
newPathstringmandatorySpecify the file or directory path to change to.
Ex) /tmp/dir2, /tmp/dir1/test2.txt
returnboolean-true : Success
false : Failure
If the parameter is abnormal, an exception occurs.

fs.remove(path)

Removes a file or directory.
If a directory is to be removed, it must be empty under that directory.

NameTypeM/OSummaryNote
pathstringmandatorySpecify a file or directory path.
Ex) /tmp/dir1, /tmp/dir1/test.txt
returnboolean-true : Success
false : Failure
If the parameter is abnormal, an exception occurs.

fs.mkdir(path[,options])

Makes a directory.
Note that recursive directory creation is not possible.

NameTypeM/OSummary                                               Note
pathstringmandatorySpecify a new directory path.
Ex) /tmp/dir2
optionsObjectoptionalOptions
Refer to Options for details.
The directory is created with owner 'root' and permission '0777'. If changed, specify the options.
returnboolean-true : Success
false : Failure
If the parameter is abnormal, an exception occurs.

fs.fcopy(srcPath,dstPath[,options])

Copies a file.
Note that the destination directory path must exist.

NameTypeM/OSummaryNote               
srcPathstringmandatorySpecify the file path to copy from.
Ex) /tmp/dir1/test.txt
dstPathstringmandatorySpecify the file path to copy to.
Ex) /tmp/dir2/test2.txt
optionsObjectoptionalOptions
Refer to Options and Additional options for details.
The owner and permissions settings of the files are inherited from the copy source. If changed, specify the options.
returnboolean-true : Success
false : Failure
If the parameter is abnormal, an exception occurs.

Additional options for .fcopy() only

NameTypeM/OSummary                                      Note
overwritebooleanoptionalFile Overwrite Settings
true: Allow overwriting.
false: Prohibits overwriting.
The default value is true.
If overwriting is prohibited and the file exists at the destination, failure occurs.

fs.fopen(path,flags[,options])

Opens a file and creates a file instance.
Note that the destination directory path must exist.

NameTypeM/OSummary                                                      Note
pathstringmandatorySpecify the file path.
Ex) /tmp/dir1/test.txt
flagsstringmandatorySpecify the open flag.
'r': Read only
'w': New write (overwrite) only
'a': Append write only
'r+': Read and write
'w+': New write (overwrite) and read
'a+': Append write and read
All are processed as binary.
optionsObjectoptionalOptions
Refer to Options and Additional options for details.
If the file is newly created, it will have owner 'root' and permission '0666'. If changed, specify the options.
return{File}, null-{File} : Generated {File}
null : If the file could not be opened
If the parameter is abnormal, an exception occurs.

Additional options for .fopen() only

NameTypeM/OSummary                                      Note
bufferingbooleanoptionalStream buffering
true: Enable (fully buffered)
false: Disable (unbuffered)
The default value is true.
Version 00.00.04+



{File}

Methods()/PropertiesSummaryVersionNote
.read()Reads data from a file.
.write()Writes data to a file.
.getStatus()Gets the file status at the present moment.
.getPosition()Gets the file position (file position indicator) at the present moment.
.setPosition()Changes the file position (file position indicator).
.sync()Transfers cache data on memory updated by file writing to the storage device.
.fcntl() / .ioctl()Executes the fcntl/ioctl command to the file descriptor handled by a file instance.00.00.04+
.close()Closes a file and releases a file resource.



Details

.read([isBin[,line[,size]]])

Reads data from a file.

NameTypeM/OSummary                               Note
isBinbooleanoptionalSpecify the readout data format.
true: Readout in binary data format
false: Readout in string format
The default value is false.
linebooleanoptional1 line readout
Reads 1 line of data up to the newline character.
true: Enable
false: Disable
The default value is false.
If the data in 1 line exceeds the maximum readout size, the data will be read out in divided readouts.
sizenumberoptionalMaximum readout size [Byte]
Range: 1 - 2,147,483,647
The default value is 4096.
returnArrayBuffer, string-Readout data
The return type is determined by isBin.
If isBin is true, the type is ArrayBuffer; otherwise, the type is string.
The readout data will be less than or equal to the maximum readout size. If there is no readout data, the size will be 0.
If the parameter is abnormal, an exception occurs.

.write(data[,flush])

Writes data to a file.

NameTypeM/OSummary                               Note
datastring, ArrayBuffermandatoryWritten data
flushbooleanoptionalStream force output
After writing data, the flash process is executed.
true: Enable
false: Disable
The default value is true.
Version 00.00.04+
returnnumber-Data size writtenIf the write fails, the result will be less than the length of the specified written data.
If the parameter is abnormal, an exception occurs.

.getStatus()

Gets the file status at the present moment.
The file status is cleared after this method is called.

NameTypeM/OSummaryNote
return{FileStatus}-{FileStatus} : File status

{FileStatus}

NameTypeSummaryNote
.eofnumberStatus of EOF (end-of-file) indicator
Whether the end of the file has been reached or not
0: Not yet reached
Other than 0: Reached
.errnumberStatus of error indicator
Whether an error occurred in the file read or write process
0: Not yet occurred
Other than 0: Occurred

.getPosition()

Gets the file position (file position indicator) at the present moment.

NameTypeM/OSummaryNote
returnnumber-Offset value at the present moment
If failed, -1 is returned.

.setPosition(offset[,whence])

Changes the file position (file position indicator).
Moves to the position from the specified whence position added the offset bytes.

NameTypeM/OSummary                                                    Note
offsetnumbermandatoryOffset
Range: -2,147,483,648 - 2,147,483,647
whencenumberoptionalReference position
0: Beginning of file
1: Current position
2: End of file
The default value is 0.
returnboolean-true : Success
false : Failure
If the parameter is abnormal, an exception occurs.

.sync([dataOnly])

Transfers cache data on memory updated by file writing to the storage device.

NameTypeM/OSummaryNote
dataOnlybooleanoptionalSpecify whether or not only data should be targeted for updating.
true: Update data only, do not update file metadata
false: Update data and file metadata
The default value is false.
returnboolean-true : Success
false : Failure
If the parameter is abnormal, an exception occurs.

.fcntl(cmd[,arg]) / .ioctl(cmd[,arg])

Executes the fcntl/ioctl command to the file descriptor handled by a file instance.

Refer to "fcntl(2)" or "ioctl(2)" in the "Linux Programmer's Manual" associated with your distribution for commands. Please note that any operations out of the command specifications may cause unexpected problems.

NameTypeM/OSummaryNote
cmdnumbermandatoryfcntl/ioctl command
Range: 0x00000000 - 0xFFFFFFFF
argnumber, ArrayBufferoptionalfcntl/ioctl command argument
number :
Used to execute commands that specify command arguments directly as numerical values.
Range: 0x00000000 - 0xFFFFFFFF
ArrayBuffer :
Used to execute commands that require a buffer pointer in the command argument.
If any of the setting commands are executed, the pre-set data to ArrayBuffer will be passed. The maximum buffer size that can be handled is 1024 bytes. If the specified ArrayBuffer size exceeds that, it will be truncated to the maximum size.
If any of the getting commands are executed, the data in the specified ArrayBuffer is overwritten and updated. If the data size written by the command exceeds the ArrayBuffer size, it is truncated to the ArrayBuffer size. Note that commands that exceed 1024 bytes of data being written by the command cannot be handled.
returnnumber-fcntl/ioctl return value
Specifications differ depending on the command handled.
In most cases, 0 on success and -1 on failure.
If the parameter is abnormal, an exception occurs.

The following is a usage example.

var cmd = 0x1234; //A command to be specified by a numerical value [dummy]
var arg = 0x0800;
var ret = file.ioctl(cmd, arg);
if(ret == 0) print('OK');
var cmd = 0x1234; //A setting command specified by a buffer pointer [dummy]
var buf = new ArrayBuffer(16);
var arr = new Uint8Array(buf);
//Parameter pre-setting
for(var i=0; i<arr.length; i++) arr[i] = 0;
arr[0] = 0x01;
var ret = file.ioctl(cmd, buf);
if(ret == 0) print('OK');
var cmd = 0x1234; //A getting command specified by a buffer pointer [dummy]
var buf = new ArrayBuffer(32);
var arr = new Uint8Array(buf);
var ret = file.ioctl(cmd, buf); //'buf' will be overwritten
if(ret == 0) {
    for(var i=0; i<arr.length; i++) print(arr[i]);
}

.close()

Closes a file and releases a file resource.

NameTypeM/OSummaryNote
returnundefined--



Object Usage Examples

Sample 1

This is a sample of file writing and file reading.
Writes a multi-line string to a file and reads it out 1 line at a time.

var filePath = '/tmp/test.txt';
var file = fs.fopen(filePath, 'w+');
file.write('abc\ndefg\nhijklmn\nopqrstuvwxyz');
file.sync();
var position = file.getPosition();
print('position: ' + position.toString());
file.setPosition(0);
while(1) {
    var str = file.read(false, true, 128);
    if(str.length) print(str.replace(/\n/g, ''));
    else break;
}
var sts = file.getStatus();
for(var key in sts) {
    print(key + ': ' + sts[key]);
}
file.close();
file = undefined;
fs.remove(filePath);

Sample 2

This is a sample of file writing and file reading.
Writes a binary to a file and reads it out.

var filePath = '/tmp/test.bin';
var file = fs.fopen(filePath, 'w+');
var wbin = new ArrayBuffer(16);
var wArr = new Uint8Array(wbin);
for(var i=0; i<wArr.length; i++) {
    wArr[i] = i;
}
file.write(wbin);
file.sync();
var position = file.getPosition();
print('position: ' + position.toString());
file.setPosition(0);
var rBin = file.read(true);
var rArr = new Uint8Array(rBin);
for(var i=0; i<rArr.length; i++) {
    print(rArr[i].toString());
}
var sts = file.getStatus();
for(var key in sts) {
    print(key + ': ' + sts[key]);
}
file.close();
file = undefined;
fs.remove(filePath);

Sample 3

This is a sample of checking the existence of directories and files, obtaining information, creating, copying, renaming, and changing permissions.

var dirPath = '/tmp/test0/';
var filePath1 = dirPath + 'test1.bin';
var filePath2 = dirPath + 'test2.bin';
var filePath3 = dirPath + 'test3.bin';

var stat = fs.stat(dirPath);
if(stat == null) {
    fs.mkdir(dirPath);
}

var file = fs.fopen(filePath1, 'w+');
file.write('0123456789ABCEDF');
file.close();
file = undefined;

print('### rename ### filePath1 to filePath2');
fs.rename(filePath1, filePath2);

var stat = fs.stat(filePath1);
print('filePath: ' + filePath1);
if(stat == null) print('no such file');
for(var key in stat) {
    print(key + ': ' + stat[key]);
}

var stat = fs.stat(filePath2);
print('filePath: ' + filePath2);
if(stat == null) print('no such file');
for(var key in stat) {
    print(key + ': ' + stat[key]);
}

print('### configure ### filePath2 0644');
fs.configure(filePath2, {permission:'0644'});

var stat = fs.stat(filePath2);
print('filePath: ' + filePath2);
if(stat == null) print('no such file');
for(var key in stat) {
    print(key + ': ' + stat[key]);
}

print('### copy ### filePath2 to filePath3');
fs.fcopy(filePath2, filePath3);

var stat = fs.stat(filePath2);
print('filePath: ' + filePath2);
if(stat == null) print('no such file');
for(var key in stat) {
    print(key + ': ' + stat[key]);
}

var stat = fs.stat(filePath3);
print('filePath: ' + filePath3);
if(stat == null) print('no such file');
for(var key in stat) {
    print(key + ': ' + stat[key]);
}

fs.remove(filePath2);
fs.remove(filePath3);
fs.remove(dirPath);



Updated: 2023-05-30
← 10. UNIXSocket12. SubProcess →
  • fs Global Object
  • Details
    • fs.stat(path)
    • {Stat}
    • fs.configure(path,options)
    • Options
    • fs.rename(oldPath,newPath)
    • fs.remove(path)
    • fs.mkdir(path[,options])
    • fs.fcopy(srcPath,dstPath[,options])
    • Additional options for .fcopy() only
    • fs.fopen(path,flags[,options])
    • Additional options for .fopen() only
  • {File}
  • Details
    • .read([isBin[,line[,size]]])
    • .write(data[,flush])
    • .getStatus()
    • {FileStatus}
    • .getPosition()
    • .setPosition(offset[,whence])
    • .sync([dataOnly])
    • .fcntl(cmd[,arg]) / .ioctl(cmd[,arg])
    • .close()
  • Object Usage Examples
    • Sample 1
    • Sample 2
    • Sample 3
AboutNewsProductsFAQPrivacy PolicyVulnerability Disclosure Policy
NEQTO Console
IntroductionFundamentalsAdministrative ActionsDevice Management NEQTO Apps
NEQTO Bridge
NEQTO Bridge ModuleNEQTO Bridge Wi-Fi ModuleNEQTO Bridge LTE-1 ModuleError Logging Event Messages
API Documentation
API UsageGlobal APIRegional APIAPI Terms of Service
Jigsaw, Inc.
© 2025 JIG-SAW INC.