Consider using the path module here - http://nodejs.org/api/path.html