Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node runs relative to Gruntfile #65

Closed
DavidGilbertsonSMS opened this issue Jun 29, 2014 · 2 comments
Closed

Node runs relative to Gruntfile #65

DavidGilbertsonSMS opened this issue Jun 29, 2014 · 2 comments

Comments

@DavidGilbertsonSMS
Copy link

I have a directory structure like this:

app
  |--client
  |--server
  |--app.js
Gruntfile.js

In the gruntfile, my script is configured as script: 'app/app.js' since effectively (correct me if I'm wrong) node is running from the position of the gruntfile. This means that I have to define static paths in my app relative to the Gruntfile like so:
app.use(express.static('app/client'));

Which means if I want to run my app elsewhere, not using grunt, I need to run node from one directory up and run node app/app.js.

In Gruntfile.js it would nice to be able to do something like

options: {
  cwd: 'app',
  script: 'app.js',
}

So paths in the app are relative to the app.js file, like so: app.use(express.static('client'));

Maybe I'm thinking of it in the wrong way, any help would be great.

@ericclemmons
Copy link
Owner

Ah, well, the best thing to do is always make relative paths into absolutes so that the cwd isn't a requirement for the app to work.

See what express-generator defaults to, as an example:

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

@DavidGilbertsonSMS
Copy link
Author

OK cool, I'll do it that way. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants