Mushtaq M A

Mushtaq M A

  • 124
  • 14.7k
  • 3.1m

How to host node js application in linux environment?

Oct 13 2023 1:51 AM

How to host node js application in a Linux environment? I am facing a "503" response after updating the startup file "app.js" with express and some additional plugins. Find the sample code below and immediate answers will be helpful to make my app available for my client.

// server.js
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const multer = require("multer");
const fs = require("fs");
const path = require("path");

// Initialize Firebase Admin SDK
// Set up multer storage and upload configuration
const storage = multer.diskStorage({
    destination: function(req, file, cb) {
        cb(null, "./uploads"); // Specify the directory where the uploaded files will be saved
    },
    filename: function(req, file, cb) {
        // Generate a random name for the uploaded file
        const randomName = Date.now() + "-" + Math.round(Math.random() * 1000) + path.extname(file.originalname);
        cb(null, randomName); // Use the random name for the uploaded file
    }
});

const upload = multer({
    storage: storage
});

app.use(express.static('public'));
app.use(express.json());

 


Answers (1)