0

Can I use Node.js with Express as a static web server? I need to upload new files to static directories based on requests from developers.

Can someone tell me how to do this using Node.js, since mostly we use CloudFoundry to deploy this Node.js app.

Laurel
  • 5,522
  • 11
  • 26
  • 49
Ramya B
  • 67
  • 5

2 Answers2

1

yes you can.

app.use(express.static(path.join(__dirname, 'public')));

whatever files uploaded inside the public folder are served as static files from your web server and it has nothing to do with deployment.

  • what do you meant by nothing to with deployment, how to upload new files to the static server without redeployment ? – Ramya B May 15 '16 at 01:34
  • 2
    you don't need to redeploy. You can ftp files to cloudfoundry public folder. –  May 15 '16 at 04:41
  • http://stackoverflow.com/questions/6084360/using-node-js-as-a-simple-web-server?rq=1 follow this question gives you more info. –  May 15 '16 at 05:02
0

Why not use the npm module serve-static Serving using express.

This is a simple example of using Express:

var express = require('express')
var serveStatic = require('serve-static')

var app = express()

app.use(serveStatic('public/ftp', {'index': ['default.html', 'default.htm']}))
app.listen(3000)

For uploading files with node.js you can see my answer here

Community
  • 1
  • 1
Tal Avissar
  • 9,063
  • 5
  • 36
  • 63
  • thanks for answering, its not about serving static files, if we deploy the server to cloudfoundry, then how can we upload new files to public directory so that new files can be accessed and how to edit old files. – Ramya B May 15 '16 at 01:23