Path: blob/master/src/packages/project/http-api/write-text-file.ts
1447 views
/*1Write a text file.23EXAMPLE:45curl -u `cat .smc/secret_token`: -d path=a.txt -d content="bar" http://localhost:`cat .smc/api-server.port`/api/v1/write-text-file6*/78import { writeFile } from "node:fs/promises";910import { client } from "./server";1112export default async function writeTextFile({ path, content }): Promise<void> {13if (client == null) throw Error("client must be defined");1415const dbg = client.dbg("write-text-file");16dbg(`path="${path}"`);17if (typeof path != "string") {18throw Error(`provide the path as a string -- got path="${path}"`);19}20if (typeof content != "string") {21throw Error(22`provide the content as a string -- got content of type ${typeof content}`23);24}2526return await writeFile(path, content);27}282930