Require
#func Require(id: str): i64Loads a Node module with require.
import node
func main:
println node.Platform().Len() > 0, node.IsWindows() == (node.Platform() == "win32")
folder := node.MkdtempSync(node.PathJoin2(node.TmpDir(), "salam-"))
path := node.PathJoin3(folder, "data", "note.txt")
println node.PathDirname(path) == node.PathJoin2(folder, "data")
fs := node.Require("fs")
_ := node.CallS1(fs, "mkdirSync", node.PathDirname(path))
node.WriteFileSync(path, "hello from node")
println node.ReadFileSync(path)
node.RmSyncRecursiveForce(folder)
obj := node.NewObject()
node.SetStr(obj, "name", "Maryam")
node.SetNum(obj, "age", 30)
node.SetBool(obj, "admin", true)
arr := node.NewArray()
node.PushStr(arr, "a")
node.Push(arr, obj)
node.SetProp(obj, "tags", arr)
println node.GetStr(obj, "name"), node.GetNum(obj, "age"), node.GetBool(obj, "admin")
println node.GetNum(node.GetProp(obj, "tags"), "length")
json := node.Global("JSON")
println node.ToStr(node.CallS1(json, "stringify", "x"))
println node.IsNullish(node.GetProp(obj, "missing")), node.ToBool(node.GetProp(obj, "admin"))
math := node.Global("Math")
println node.ToStr(node.CallV2(math, "max", node.GetProp(obj, "age"), node.GetProp(obj, "age")))
date := node.New1(node.Global("Date"), node.GetProp(obj, "age"))
println node.ToStr(node.Call0(date, "getTime"))
path_module := node.Require("path")
println node.ToStr(node.CallS2(path_module, "join", "a", "b"))
println node.ToStr(node.CallS3(path_module, "join", "a", "b", "c"))
node.SetPropFn0(obj, "hello", (): println "hello from a function" end)
_ := node.Call0(obj, "hello")
node.SetPropFn1R(obj, "twice", (x: i64): ret node.CallV2(math, "max", x, x) end)
println node.ToStr(node.Invoke1(node.GetProp(obj, "twice"), node.GetProp(obj, "age")))
println node.IsNullish(node.Exports())
end