Menu

Write a file in Node | NodeJS tutorial

In Node using FileSystems, developer can perform the various file operations, create file, add content into file, delete file.

First import the FileSystems fs using the below node code

const fs = require('fs')


Then, using the Node FIleSystems object fs we could perform the form operations. Liek below.

fs.writeFileSync('notes.txt', 'This file is created by NodeJS application. ')


writeFileSync will create and write the first data into the file. writeFileSynch method have two parameters, first file name and second data.


Next if we want to add or append data into an existing file then use appendFileSync method. Like Below.

fs.appendFileSync('notes.txt', 'DO NOT DELETE THIS FILE')


Hope this help you to understand the basic of file systems in NodeJS.

Failed to construct 'Text': Please use the 'new' operator

Failed to construct 'Text': Please use the 'new' operator, this DOM object constructor cannot be called as a function.

Resolution

We did not import anything Text in the React Component. Hence, component is fail to understand this. Import the Text from the source.

e.g. import { Text } from 'ReactFile.js'

React.createElement: type is invalid -- expected a string

React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

If you are seeing this error that means you are using any element that is either not imported or not getting resolved in your render.

Resolution 1

Check the elements that are being use and their import.

Resolution 2

Change the return statement and try to return without function sign. refere Stackoverflow | React.createElement: type is invalid -- expected a string


Hope this help you to resolve the error.