0

I created a simple node js application with Node and Express. It just used to serve couple of static files. It is serving files as

http://localhost:3000/index
http://localhost:3000/users

But I want to serve it with a project name. some thing like as follows

http://localhost:3000/myNodeProject/index
http://localhost:3000/myNodeProject/index

How do I do that ?

My Code

var express = require('express');
var path = require('path');

var routes = require('./routes/index');
var users = require('./routes/users');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

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

//Routers or HTTP Rest Requests
app.use('/', routes);
app.use('/users', users);

var server = http.createServer(app);
user3470629
  • 511
  • 1
  • 8
  • 20
  • 1
    I don't think it works like that. Nodejs sets up its own server and you can access that at root level. You can use different ports for different projects. You can use the url pattern you mentioned by mounting different roots. – Mohit Bhardwaj Oct 14 '16 at 07:12
  • Mohit is right, however in production. You can use something like Apache or Nginx to forward anything that starts with http://localhost:3000/myNodeProject to your Node.Js application. You are able to do this in development too, however it doesn't grant any benefits. – Teun Oct 14 '16 at 07:15
  • http://stackoverflow.com/questions/17516810/how-to-assign-a-domain-name-to-node-js-server take a look at this question – Priyamal Oct 14 '16 at 07:46

0 Answers0