npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

save-file-npm

v1.0.0

Published

With this incredible package, managing file uploads has never been easier! You can now simply use the saveFile() method with your inputs and directory, and watch as it handles all the logic for you. The inputs can be of any type - file-object (image, PDF,

Downloads

223

Readme

Save File Functionality

This function allows you to save a file to a specified folder on the server. It accepts various input types including URLs, base64 strings, and file objects.

Installation

npm install save-file-npm

Live DEMO:

Usage

saveFile(source, folder, fileName?, req?) Uploads a file from the given source to the specified folder. The fileName parameter is optional and can be used to set a custom name for the uploaded file. The req parameter is also optional and can be used to get the full URL of the uploaded file.

Parameters

The saveFile function takes in the following parameters:

  • file: This can be an object, string, or base64 data representing the file you want to save. It is a required parameter.
  • folderName: This is a string representing the name of the folder where the file will be saved. It is a required parameter.
  • fileName (optional): This is an optional parameter that allows you to set a custom file name for the saved file.
  • req (optional): This is an optional parameter that can be used to retrieve the current full file URL if needed. Examples

Here are some examples of how to use the saveFile function:

Import the "getColumnSum" function into your component or service by adding the following code:

const saveFile = require('save-file-npm');

const saveFile = require('save-file-npm');

// Upload a file from a URL to a folder
	saveFile('https://pbs.twimg.com/profile_images/1410074091965403139/IqExKETZ_400x400.jpg', 'new_dir_1')
	.then(result => {
		console.log(result);
	})
	.catch(err => console.log(err));

// Upload a file from a URL to a folder and get the full URL
	saveFile('https://pbs.twimg.com/profile_images/1410074091965403139/IqExKETZ_400x400.jpg', 'new_dir_1', null, req)
	.then(result => {
		console.log(result);
	})
	.catch(err => console.log(err));

// Upload a file from a base64-encoded string to a folder
	saveFile(base64, 'new_dir_1')
	.then(result => {
		console.log(result);
	})
	.catch(err => console.log(err));

// Upload a file from a file object to a folder
	const fileObject = req.file;
	saveFile(fileObject, 'new_dir_1')
	.then(result => {
		console.log(result);
	})
	.catch(err => console.log(err));

// Upload a file from a file object to a folder and get the full URL
	saveFile(fileObject, 'new_dir_2', null, req)
	.then(result => {
		console.log(result);
	})
	.catch(err => console.log(err));

// Upload a file from a URL to a folder with a custom file name and get the full URL
	saveFile('https://pbs.twimg.com/profile_images/1410074091965403139/IqExKETZ_400x400.jpg', 'new_dir_2', 'new-logo-name', req)
	.then(result => {
		console.log(result);
	})
	.catch(err => console.log(err));

Conclusion

This saveFile function is a simple and effective way to save files to a server using a variety of input types. If you have any questions or issues using this function, please don't hesitate to reach out for support.