Interesting problem, Using harp to build a simple app, then deploying it to Heroku, which is proving to be an issue. The last deploy worked flawlessly using the Harp buildpack, But now it's breaking on deploy.
Nothing has changed that should be causing this, no updates to node modules, or node version. the logs and Papertrail are complaining:
Error: `libsass` bindings not found. Try reinstalling `node-sass`?
After this, I branched off and tried to check on lib-sass in
/app/node_modules/harp/node_modules/terraform/node_modules/node-sass/lib/index.js:22
As per the logs, tried reinstalling it, but no avail. Anyone ever run into this? could it be a problem with the buildpack?
seems to be an issue with Node 0.12.
https://github.com/zeke/harp-buildpack/issues/12
I was able to get my app running by just not using the buildpack, adding
"dependencies": {
"harp": "~0.12.1"
},
"scripts": {
"start": "node server.js"
},
"engines": {
"node": "0.10.x"
},
to package.json and adding a server.js with
require('harp').server(__dirname, { port: process.env.PORT || 9000 })
Related
I am very new to server side scripting. And I am using NodeJS. My Problem is that after adding some new features to the app, i.e. after changing the code, these changes will be applied only after restarting the server. Till then NodeJS behaves so as though I hadn't changed anything. So for instance if I add console.log("works") and don't restart the server, then it hasn't any effect.
I am using Nuxt.js, which is actually the Vue.js framework but with additional and very usefull features mainly for server side rendering. I didn't integrate the express.js at the beginning of the project, beacause it wasn't planned to write any server side code. So I am normally exporting express and using it, which is pretty fine for me, since I need just a couple lines of code to use the NodeJS file system.
So, as it is pretty hard to code, if I should restart the server once I changed anything, I want to ask you if there is any solution to this problem.
Use nodemon
step 1 : npm install -g nodemon <- this will install nodemon globaly in your system
step 2 : change your start script within package.json
"scripts": {
"start": "nodemon fileName" <- like this //filename is you root file which starts the app like app.js
}
step 3 : npm start
This is already build in into nuxt. You just need to run it in dev mode, not in production.
E.g. for dev with change monitoring
nuxt
For production without monitoring
nuxt start
So in this particular case the following changes to the "scripts" in package.json have solved my problem.
"scripts": {
"dev": "nodemon --watch api --exec \"nuxt\"",
"start": "nodemon nuxt",
}
The following link could also be usefull to you.
Install nodemmon in your application to allow live update npm -g install nodemon
and add the following codes inside your packages json file :
"main": "app.js",
"scripts": {
"start": "node app"
},
on your command line, just type : start
I'm new to Heroku, a little bit less to NodeJS (and Nodemon).
I am now using heroku local to run my app in local (and be as close as possible to my prod environment) but I'd like to have my app rebuilt and restarted everytime I make a change in local (as with Nodemon for example).
Is there nay way to do this with heroku local?
Thanks!
Nicolas.
Old question, I know, but came up while I was searching for the same. There is an answer here: https://stackoverflow.com/a/46561121
This is what I have in my package.json:
"scripts": {
"start": "nodemon --exec 'heroku local' --signal SIGTERM"
}
For anybody coming across this post in search of a solution. As mentioned by nicolasdaudin in response to tom, you can add nodemon to the heroku Procfile (https://devcenter.heroku.com/articles/procfile):
web: nodemon index.js
Note that nodemon must be installed globally for this to work:
npm i -g nodemon
Then you should be able to run heroku locally as normal with nodemon watching for changes:
heroku local web
Getting started with NPM...
I can run the following command to start my app.
node app
But when I run the following command, I get the following error:
npm start
Windows Script Host
Object expected
Line 2
800A138F
Microsoft JScript runtime error
App.js:
var port = 5000;
var express = require('express');
Package.json:
{
"name": "2",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "app.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.13.3"
}
}
And I've run this command of course:
npm install express --save
Seems like NPM can't find the express package? Why not?
I know its too late to answer, but in case any wanderer like me faces the same problem in future..
Solution:
need to add node keyword ahead of app.js in script. So, start script should
"scripts": {
"start": "node app.js"
},
That solved for me.
I had this problem as well. The .js files are associated with the Microsoft Script Engine. Some suggested that we dis-associate the extension with the program, but I do not think that is necessary. I was able to fix the issue with the following instruction that I found in the NODE Docs.
Please make sure that your file(s) referenced in bin starts with
#!/usr/bin/env node
otherwise the scripts are started without the node executable!
Use >node app.js instead of >app.js
Then it will work
When I faced the same problem using Visual Studio Code, I was trying to run localhost at port 8080, however by pressing F5 I was able to know that the port was already taken and so I changed the port to 3000, and viola! that worked for me.
Check out the error
If you're using Visual Studio Code, it may have taken over running the script. If in VS Code, hit F5 and see if the project runs properly.
I don't know why it does this, but did for me. This tipped me off
I am new to the whole nodejs/reactjs world so apologies if my question sounds silly. So I am playing around with reactabular.js.
Whenever I do a npm start it always runs on localhost:8080.
How do I change it to run on 0.0.0.0:8080 to make it publicly accessible? I have been trying to read the source code in the above repo but failed to find the file which does this setting.
Also, to add to that - how do I make it run on port 80 if that is at all possible?
Something like this worked for me. I am guessing this should work for you.
Run webpack-dev using this
webpack-dev-server --host 0.0.0.0 --port 80
And set this in webpack.config.js
entry: [
'webpack-dev-server/client?http://0.0.0.0:80',
config.paths.demo
]
Note If you are using hot loading, you will have to do this.
Run webpack-dev using this
webpack-dev-server --host 0.0.0.0 --port 80
And set this in webpack.config.js
entry: [
'webpack-dev-server/client?http://0.0.0.0:80',
'webpack/hot/only-dev-server',
config.paths.demo
],
....
plugins:[new webpack.HotModuleReplacementPlugin()]
This is how I did it and it seems to work pretty well.
In you webpack.config.js file add the following:
devServer: {
inline:true,
port: 8008
},
Obviously you can use any port that is not conflicting with another. I mention the conflict issue only because I spent about 4 hrs. fighting an issue only to discover that my services were running on the same port.
Configure webpack (in webpack.config.js) with:
devServer: {
// ...
host: '0.0.0.0',
port: 80,
// ...
}
I am new to JavaScript development and ReactJS. I was unable to find an answer that works for me, until figuring it out by viewing the react-scripts code. Using ReactJS 15.4.1+ using react-scripts you can start with a custom host and/or port by using environment variables:
HOST='0.0.0.0' PORT=8080 npm start
Hopefully this helps newcomers like me.
Following worked for me -
1) In Package.json add this:
"scripts": {
"dev": "webpack-dev-server --progress --colors"
}
2) In webpack.config.js add this under config object that you export:
devServer: {
host: "GACDTL001SS369k", // Your Computer Name
port: 8080
}
3) Now on terminal type: npm run dev
4) After #3 compiles and ready just head over to your browser and key in address as http://GACDTL001SS369k:8080/
Your app should hopefully be working now with an external URL which others can access on the same network.
PS: GACDTL001SS369k was my Computer Name so do replace with whatever is yours on your machine.
I struggled with some of the other answers. (My setup is: I'm running npm run dev, with webpack 3.12.0, after creating my project using vue init webpack on an Ubuntu 18.04 virtualbox under Windows. I have vagrant configured to forward port 3000 to the host.)
Unfortunately putting npm run dev --host 0.0.0.0 --port 3000 didn't work---it still ran on localhost:8080.
Furthermore, the file webpack.config.js didn't exist and creating it didn't help either.
Then I found the configuration files are now located in build/webpack.dev.conf.js (and build/webpack.base.conf.js and build/webpack.prod.conf.js). However, it didn't look like a good idea to modify these files, because they actually read the HOST and PORT from process.env.
So I searched about how to set process.env variables and achieved success by running the command:
HOST=0.0.0.0 PORT=3000 npm run dev
After doing this, I finally get "Your application is running here: http://0.0.0.0:3000" and I'm finally able to see it by browsing to localhost:3000 from the host machine.
EDIT: Found another way to do it is by editing the dev host and port in config/index.js.
If you're in a React Application created with 'create-react-app' go to your package.json and change
"start": "react-scripts start",
to ... (unix)
"start": "PORT=80 react-scripts start",
or to ... (win)
"start": "set PORT=3005 && react-scripts start"
Following worked for me in JSON config file:
"scripts": {
"start": "webpack-dev-server --host 127.0.0.1 --port 80 ./js/index.js"
},
I feel dirty for telling you this b/c of the security implications of what you're trying to do, but here you go.
npm run dev -- -h 0.0.0.0 -p 80
For me: changing the listen host worked:
.listen(3000, 'localhost', function (err, result) {
if (err) {
console.log(err);
}
console.log('Listening at localhost:3000');
});
was changed to :
.listen(3000, '0.0.0.0', function (err, result) {
if (err) {
console.log(err);
}
console.log('Listening at localhost:3000');
});
and the server started listening on 0.0.0.0
I tried the solutions above, but had no luck. I noticed this line in my project's package.json:
"bin": {
"webpack-dev-server": "bin/webpack-dev-server.js"
},
I looked at bin/webpack-dev-server.js and found this line:
.describe("port", "The port").default("port", 8080)
I changed the port to 3000. A bit of a brute force approach, but it worked for me.
For me, this code worked. Just add it on your package.json file :
"scripts": {
"dev-server": "encore dev-server",
"dev": "webpack-dev-server --progress --colors",
"watch": "encore dev --watch",
"build": "encore production --progress"
},
And run the script "build" by running npm run build
For windows create file runMobile.bat
set PORT=8081
set HOST=192.168.3.20
npm run dev
I tried this to easily use another port:
PORT=80 npm run dev
When Openshift creates a Node.js cartridge it includes a version of Express 3. My app is an Express 4 app and fails to start under the default Openshift setup. Even if my app's package.json has the line "express": ">=4.9.0" in dependencies.
4.9.0 happens to be the version that is embedded in my app's project but is ignored by Openshift when started there. So apparently I need to update Openshift's version to 4. I can confirm that the app works as designed and intended on my local computer.
How do I update Openshift's Express, which is outside the app, from version 3 to 4 ?
I made sure that my /package.json includes something like this under dependencies:
"express": "~4.11.1"
Personally, I retired my /bin/www content by removing that out of /package.json:
...
"scripts": {
"start": "node server.js"
},
"main": "server.js"
}
...and migrated much of /bin/www back into /server.js.
That seemed to be the only way I could get Express4 to work on OpenShift.
/server.js needs a shebang a the top "#!/bin/env node"
/package.json gets the mod above
I've got my Express4 app running now with MongoDB support. Seems to be happy. Pushes/builds/logs success.
Which works for me is:
"main": "./bin/www",
"scripts": {
"start": "node ./bin/www"
}