Skip to content

Instantly share code, notes, and snippets.

Last active Jun 14, 2021
What would you like to do?
// Import express into our project
const express = require("express");
// Import multer
const multer = require("multer");
// Creating an instance of express function
const app = express();
// The port we want our project to run on
const PORT = 3000;
// Express should add our path -middleware
// Body parser
app.use(express.urlencoded({ extended: false }));
// Multer file storage
const Storage = multer.diskStorage({
destination: function (req, file, callback) {
callback(null, "./attachments");
filename: function (req, file, callback) {
callback(null, `${file.fieldname}_${}_${file.originalname}`);
// Middleware to get attachments
const attachmentUpload = multer({
storage: Storage,
// Root directory -homepage
app.get("/", (req, res) => {
// Route to handle sending mails"/send_email", (req, res) => {
attachmentUpload(req, res, function (error) {
if (error) {
return res.send("Error uploading file");
} else {
const recipient =;
const subject = req.body.subject;
const message = req.body.message;
const attachmentPath = req.file.path;
console.log("recipient", recipient);
console.log("subject", subject);
console.log("message", message);
console.log("attachmentPath", attachmentPath);
// Express allows us to listen to the port and trigger a console.log() when you visit the port
app.listen(PORT, () => {
console.log(`Server is currently 🏃‍♂️ on port ${PORT}`);

This comment has been minimized.

Copy link
Owner Author

@unclebay143 unclebay143 commented Jun 14, 2021

changed file name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment