dev-resources.site
for different kinds of informations.
Upload File di Node JS
Published at
4/11/2024
Categories
node
webdev
file
upload
Author
juanangelaalma
Author
14 person written this
juanangelaalma
open
Apa itu Node JS?
Node JS merupakan run time environment pada javascript yang didesain untuk membuat aplikasi website menggunakan bahasa pemrograman javascript. Pada jaman dahulu javascript dikenal sebagai bahasa pemrograman yang berjalan di sisi client, namun sekarang javascript dapat berjalan di sisi server
Apa saja yang akan kita butuhkan?
- Node JS
- Package Manager (npm, yarn, etc)
- Text editor
- Formidable
Step 1
Install package formidable
npm install formidable
Step 2
Buat form.html di dalam folder project node js. Form ini akan digunakan untuk field upload file
<form action="upload" method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit">
</form>
Step 3
Buat server.js yang akan menjadi server untuk upload file
const http = require('http')
const formidable = require('formidable')
const fs = require('fs')
const server = http.createServer((req, res) => {
if(req.url == '/upload') {
const form = new formidable.IncomingForm()
form.parse(req, (err, fields, files) => {
const oldPath = files.file.path
const newPath = './files/'+files.file.name
fs.rename(oldPath, newPath, (err) => {
if(err) throw err
res.write('File uploaded')
res.end()
})
})
} else {
fs.readFile('./form.html', 'utf8', (err, data) => {
if(err) throw err
res.writeHead(200, {'Content-Type': 'text/html'})
res.write(data)
res.end()
})
}
})
server.listen(8080, () => {
console.log('server running at 8080')
})
yang terakhir jangan lupa untuk membuat folder file yang digunakan untuk menyimpan file yang telah diupload
upload Article's
30 articles in total
UploadThing: A Modern File Upload Solution for Next.js Applications
read article
NestJS - Armazenamento nas nuvens
read article
NestJS - criar um endpoint para upload de diversos arquivos
read article
NestJS - Validando o envio de arquivos
read article
NestJS - Armazenamento local de upload
read article
NestJS - criar endpoint para upload de 1 arquivo
read article
Next.js: Upload de imagem para a Cloudflare R2 Utilizando Presigned URL
read article
A file uploader built with shadcn/ui and react-dropzone
read article
Elevate Your GraphQL API: Mastering File Uploads with Yoga GraphQL
read article
Mastering File Uploads in Laravel 11: A Comprehensive Guide
read article
How To Upload Multiple File In Laravel 10
read article
Different approaches to reduce AWS S3 file upload time using AWS-SDK v3 in NodeJS.
read article
How would you handle image upload?
read article
Upload File di Node JS
currently reading
Uploading Images with Node.js and React.js
read article
Simplifying AWS S3 File Uploads with the Android Library
read article
Laravel 10 Crop Image Before Upload Cropper Js
read article
Enhance Job Seeker Experience: Quick Image Upload for Portals
read article
A file upload sample with NextJs
read article
Azure Storage Account: Unleash the Potential of Cloud-Based Storage
read article
Spheron Network: Browser Upload
read article
Uploading files from terminal on file hosting service, and unlimited cloud storage
read article
Process FormData file sent to Node server
read article
Express file upload using Multer
read article
Maximize Your Client Upload Efficiency with the Bulk Upload
read article
Upload images in Ckeditor 5 with Laravel
read article
Eteot Logo
read article
Install & Upload WordPress Plugin
read article
Laravel 9 Multiple Image Upload Example
read article
How To Enhance JavaScript File Upload In Your Web App
read article
Featured ones: