grunt-express-server icon indicating copy to clipboard operation
grunt-express-server copied to clipboard

not running correct app; cwd problems

Open waffledonkey opened this issue 8 years ago • 2 comments

I have app.js in the root directory and I do a build; copying app.js to 'dist'. I then have grunt-express-server configured to use the script path.join(dist, pkg.main) -- in other words dist/app.js. The server starts, but it appears to be running app.js out of root, not out of dist. I know this because part of the dist build is generating a sass stylesheet and replacing the non-sass one. When I view the stylesheet in the browsers inspector from the running grunt-express-server process it's not the sass one. If I cd into dist and just start the app (node app) the resulting stylesheet is the sass-based one. Similarly if I'm in the root directory and I say node dist/app it's not the sass-based one. So it may not be an express-server problem per se, it may be with node itself however if you had a cwd option versus what script should I start and I'll just run from root it seems like it might be fixable.

kind regards,

waffledonkey avatar May 11 '16 20:05 waffledonkey

I had a similar problem to this, take a look at my Stack Overflow question:

http://stackoverflow.com/questions/40238362/running-grunt-express-server-causes-error-enoent-no-such-file-or-directory-op

owensgit avatar Oct 25 '16 12:10 owensgit

I did and I'm glad your advice worked for the OP. Using __dirname would have worked, but I'd have to solve for the path in node and then pass it to the template via app.locals and... I don't know... it felt kind of clumsy; especially if it had to be applied to all external resources.

Instead I solved my issue by forcing the process current working directory to be that of __dirname by dropping process.chdir(__dirname); in my "app" js and now js templates, Sass (in my case) and grunt-express-server (along with copy, newer and livereload) all play nice with one another.

waffledonkey avatar Oct 25 '16 21:10 waffledonkey