About 10,300,000 results
Open links in new tab
  1. How to Save a Node.js Script - DEV Community

    Nov 6, 2023 · Here are a few ways to save and run a Node.js script: 1. Create a .js File. To save a Node.js script, simply create a new text file with a .js extension. For example: You can create this in any text editor like Visual Studio Code, Sublime Text, Atom, etc. 2. Add Node.js Code. In the .js file, write your Node.js code. For example:

  2. javascript - Node.js get file extension - Stack Overflow

    Jun 21, 2019 · I believe you can do the following to get the extension of a file name. var path = require('path') path.extname('index.html') // returns '.html' If you would like to get all extensions in a file name (e.g. filename.css.gz => css.gz), try this:

  3. node.js - How to store a file with file extension with multer?

    Jul 23, 2015 · In order to figure out the right extension you can make use of mime-types. npmjs.com/package/mime-types. This works for me too. With path.extname (file.originalname), you don't need to provide the dot (.) to build a filename.

  4. Writing files with Node.js

    The easiest way to write to files in Node.js is to use the fs.writeFile() API. Alternatively, you can use the synchronous version fs.writeFileSync(): You can also use the promise-based fsPromises.writeFile() method offered by the fs/promises module: By default, this API will replace the contents of the file if it does already exist.

  5. How can I save a file in Node.js? - Stack Overflow

    The code of your Node.js file should be like this: ws.on('message', function (message) { var fs = require('fs'); fs.writeFile("/tmp/test", message, function (err) { if (err) { return console.log(err); } console.log("The file was saved!");

    Missing:

    • Extension

    Must include:

  6. 5 Ways To Create & Save Files In Javascript (Simple Examples)

    May 3, 2024 · The possible ways to create and save files in Javascript are: Create a blob object and offer a “save as”. Upload the data, save it on the server. Create a writable file stream. In NodeJS, simply use the file system module – require("fs").writeFile("demo.txt", "Foo bar!");

  7. Node.js File System Module - W3Schools

    The Node.js file system module allows you to work with the file system on your computer. To include the File System module, use the require() method: var fs = require('fs');

    Missing:

    • Extension

    Must include:

  8. How do I save a file in node JS? – Technical-QA.com

    Writing to a file is another of the basic programming tasks that one usually needs to know about – luckily, this task is very simple in Node. js. We can use the handy writeFile method inside the standard library’s fs module, which can save all sorts of time and trouble.

  9. Executing and Saving JavaScript in a web browser / Node

    Mar 22, 2020 · Use Ctrl + S to save the file. To perform other function like renaming, removing, run and save as, right-click on the file name and the options will pop up. Note: The difference between using...

  10. How to Save Text to A File in Node.js - Orangeable

    In this tutorial, you'll learn how to save text to a file in Node.js using the built-in File System module. Code Example. Here is a quick code example, saving the text "Hello There!" to a file named my_test.txt: import fs from "node:fs"; const my_string = "Hello There!"; fs.writeFile("my_test.txt", my_string, (err) => { if (err) { console.error ...

  11. Some results have been removed
Refresh