I've started a new socket.io project with heroku. The server runs fine locally on windows. I start it with npm start but when I shut it down with ctrl + c I get this error in the console:
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\
node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v6.11.4
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! test1#1.0.0 start: `node index.js`
npm ERR! Exit status 3221225786
npm ERR!
npm ERR! Failed at the test1#1.0.0 start script 'node index.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the test1 package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node index.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs test1
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls test1
npm ERR! There is likely additional logging output above.
I have searched for a solution but the very little I have been able to find has given no solution. I've tried updating npm and node, running npm install again, clearing the npm cache and probably some other actions I can't recall.
Here is my index.js
const express = require('express');
const socketIO = require('socket.io');
const path = require('path');
const PORT = process.env.PORT || 3000;
const server = express()
.use(express.static(__dirname + '/client'))
.listen(PORT, () => console.log(`Listening on ${ PORT }`));
const io = socketIO(server);
const pg = require('pg');
var connectionString = "postgres://jdirjtnfueksiw:823e80fbae9599f0d6797f82342d83bccf1caea764b8a1659356f3ee89r69f94#ec1-78-222-138-451.compute-1.amazonaws.com:5432/jf84jd75jgu26d5?ssl=true";
pg.connect(connectionString, function(err, client, done) {
if (err) {
throw err;
}
else {
console.log('Database connection test successful');
}
});
io.on('connection', function (socket) {
socket.emit('connected');
console.log('New connection from ' + socket.request.connection.remoteAddress);
socket.on('disconnect', function () {
console.log('Player left');
});
});
my package.json
{
"name": "test1",
"version": "1.0.0",
"engines": {
"node": "6.11.4"
},
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"pg": "6.x",
"express": "4.13.4",
"socket.io": "1.4.6"
},
"devDependencies": {},
"description": ""
}
Thank you for any help.
In the index.js can you try putting the following code:
process.on('SIGINT', () => {
process.exit();
});
I think the issue is that Ctrl+C kills the application but there is still some process running in the background. This will ensure that it is terminated.
Hope this helps!
Related
I am trying to create a Full Stack Node & Vue application that takes data from an API. I am running into an issue where I am trying to run both the client and server concurrently but the code is running into an error. Please bear with me if I am structuring this question wrong as I am still fairly new to coding!
This is the following error log:
[0] Error occurred when executing command: npm run server
[0] Error: spawn cmd.exe ENOENT
[0] at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
[0] at onErrorNT (internal/child_process.js:469:16)
[0] at processTicksAndRejections (internal/process/task_queues.js:84:21)
[1] Error occurred when executing command: npm run client
[1] Error: spawn cmd.exe ENOENT
[1] at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
[1] at onErrorNT (internal/child_process.js:469:16)
[1] at processTicksAndRejections (internal/process/task_queues.js:84:21)
[1] npm run client exited with code -4058
[0] npm run server exited with code -4058
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! apex-tracker#1.0.0 dev: `concurrently "npm run server" "npm run client"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the apex-tracker#1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
From what I can tell the program is running fine up until it reaches the "dev" script in my package.json:
{
"name": "apex-tracker",
"version": "1.0.0",
"description": "Apex Legends user statistics tracker",
"main": "server.js",
"scripts": {
"start": "node server",
"server": "nodemon server",
"client": "npm run serve --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\""
},
"author": "Jared Mackay",
"license": "MIT",
"dependencies": {
"concurrently": "^5.0.1",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"morgan": "^1.9.1",
"node-fetch": "^2.6.0"
},
"devDependencies": {
"nodemon": "^2.0.2"
}
}
prior to the errors, the program ran fine when I ran the npm run server command, however upon installing the client folder and adding the client and dev script that's when I ran into my errors.
Here is my server.js that I am trying to run with the client:
const express = require('express');
const morgan = require('morgan');
const dotenv = require('dotenv');
//Load configuration file
dotenv.config({ path: './config.env' })
const app = express();
//Develper logging
if (process.env.NODE_ENV === 'development') {
app.use(morgan('dev'));
}
//Profile routes
app.use('/api/v1/profile', require('./routes/profile'));
const port=process.env.PORT || 8000;
app.listen(port, () => {
console.log(`Server running on ${process.env.NODE_ENV} mode on port ${port}`);
});
I've tried clearing the npm cache, deleting and reinstalling node-modules as well as package-lock.json, but this created more issues rather than fixing them. I had to revert back to an old git commit and now I'm stuck.
I don't think this route .js file is an issue but here it is just in case profile.js:
const express = require('express');
const router = express.Router();
const fetch = require('node-fetch');
router.get('/:platform/:gamertag', async (req, res) => {
try {
const headers = {
'TRN-Api-Key': process.env.TRACKER_API_KEY
}
const { platform, gamertag } = req.params;
const response = await fetch(
`${process.env.TRACKER_API_URL}/profile/${platform}/${gamertag}`,
{
headers
}
);
const data = await response.json();
if(data.errors && data.errors.length > 0) {
return res.status(404).json({
message: 'Profile Not Found'
});
}
res.json(data);
} catch (err) {
console.error(err);
res.status(500).json({
message: 'Server Error'
});
}
});
module.exports = router;
Thank you in advance!
spawn cmd.exe ENOENT
Your program does not know where to find cmd.exe.
I am running into the error
An error occurred in the application and your page could not be served.
when running 'heroku open' command. On heroku dashboard it says deployed successfully but then it will not run 'it is working' from the app.get line of code.
server.js
const express = require('express');
const bodyParser = require('body-parser');
const bcrypt = require('bcrypt-nodejs');
const cors = require('cors');
const knex = require('knex');
const register = require('./controllers/register');
const signin = require('./controllers/signin');
const profile = require('./controllers/profile');
const image = require('./controllers/image');
const db = knex({
client: 'pg',
connection: {
host : '127.0.0.1',
user : 'benjohnson',
password : '',
database : 'smart-brain'
}
});
const app = express();
app.use(cors());
app.use(bodyParser.json());
app.get('/', (req, res)=> { res.send('its working!') })
app.post('/signin', signin.handleSignin(db, bcrypt))
app.post('/register', (req, res) => { register.handleRegister(req, res, db, bcrypt) })
app.get('/profile/:id', (req, res) => { profile.handleProfileGet(req, res, db)})
app.put('/image', (req, res) => { image.handleImage(req, res, db)})
app.post('/imageurl', (req, res) => { image.handleApiCall(req, res)})
app.listen(process.env.PORT || 3000, ()=> {
console.log(`app is running on port ${process.env.PORT}`);
})
When running the server.js file within the heroku cli i receive the error, when running 'heroku logs --tail' i receive this error?
> node#1.0.0 start /Users/benjohnson/.Trash
> nodemon server.js
sh: nodemon: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! node#1.0.0 start: `nodemon server.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the node#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likel
y additional logging output above.
npm WARN Local package.json exists, but node_modules missing, di
d you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/benjohnson/.npm/_logs/2019-09-25T14_11_11_91
0Z-debug.log
The error is about nodemon.
Open the package.json, is at the same folder with server.js
Find:
"scripts": {
"start": " nodemon server.js",
},
And replace it with:
"scripts": {
"start": "node server.js",
"start:dev": "nodemon server.js"
},
Upload again in Heroku.
When you want to run the project locally, just run in your terminal npm start:dev and it will load server.js with nodemon.
I have been searching the whole day the reason of that problem so i've decided to post it:
I can't run my server using PORT=80 npm start
I get the following message :
Port 80 requires elevated privileges
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! server#0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the server#0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/ubuntu/.npm/_logs/2018-03-26T19_52_49_813Z-debug.log
ubuntu#ip-172-31-32-30:~/mean/server$
Here is my code :
Package.json
{
"name": "server",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www",
"prod": "PORT=80 node ./bin/www"
},
"dependencies": {
"body-parser": "~1.18.2",
"cookie-parser": "~1.4.3",
"debug": "~3.1.0",
"express": "~4.16.2",
"jade": "~1.11.0",
"mongoose": "^5.0.1",
"morgan": "~1.9.0",
"serve-favicon": "~2.4.5"
}
}
my app.js
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var logger = require('morgan');
const mongoose = require('mongoose');
var app = express();
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname,'../public')))
mongoose.connect('mongodb://XXXXX:XXXXXX#ds12XXXX.mlab.com:2XXXX/angularXXXX', {}, (err) => {
if (err) {
console.log(err);
} else {
console.log('db connection ok!');
}
});
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '../public/index.html'))
})
module.exports = app;
I'm using :
NPM : 5.6.0
NODE : 8.10.0
Already tried : uninstall modules and npm install again, restart AWS instance, checked if port 80 is already used
Thank you for your help
It's not your code — you can't connect to port 80 from an app started with non-root account. You could sudo the node app, but that's not a great practice.
There are a lot of ways to fix this, which you can easily find in a search, but the easiest is to just alter the iptables with something like:
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080
Now you can run your node app on 8080, but reach it through port 80. If you run:
sudo iptables -t nat -L
it will show you something like:
target prot opt source destination
REDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 8080
I think this is a pretty common solution if you're just looking for a quick fix.
Im doing migration to parse server. And until now everything worked well. But now I want to add google cloud storage file adapter and if I add this line to my code it stops working. Can you somebody tell me why.
var GCSAdapter = require('parse-server-gcs-adapter');
This is the log:
npm ERR! Linux 3.13.0-105-generic
npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
npm ERR! node v6.9.1
npm ERR! npm v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! parse-server-example#1.4.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the parse-server-example#1.4.0 start script 'node index.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the parse-server-example package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node index.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs parse-server-example
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls parse-server-example
npm ERR! There is likely additional logging output above.
2017-01-29T16:56:58.161879+00:00 app[web.1]:
npm ERR! Please include the following file with any support request:
npm ERR! /app/npm-debug.log
My index.js file:
// Example express application adding the parse-server module to expose Parse
// compatible API routes.
var express = require('express');
var ParseDashboard = require('parse-dashboard');
var ParseServer = require('parse-server').ParseServer;
var GCSAdapter = require('parse-server-gcs-adapter');
var path = require('path');
var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
if (!databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'myAppId',
masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
// liveQuery: {
// classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
// }
// filesAdapter: new GCSAdapter(
// "oval-proxy-117311",
// "./SymboloKey",
// "Symbolo",
// {directAccess: true}
// )
});
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
// If you wish you require them, you can set them as options in the initialization above:
// javascriptKey, restAPIKey, dotNetKey, clientKey
const dashboard = new ParseDashboard( {
'allowInsecureHTTP': true,
'apps': [
{
'serverURL': process.env.SERVER_URL,
'appName': 'Symbolo',
'appId': process.env.APP_ID,
'masterKey': process.env.MASTER_KEY
}
],
'users': [
{
'user': 'public',
'pass': 'qwerty'
}
]
}, true )
var app = express();
// Serve static assets from the /public folder
app.use('/public', express.static(path.join(__dirname, '/public')));
// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);
// serve the Parse Dashboard
app.use('/dashboard', dashboard)
// Parse Server plays nicely with the rest of your web routes
app.get('/', function(req, res) {
res.status(200).send('I dream of being a website. Please star the parse-server repo on GitHub!');
});
// There will be a test page available on the /test path of your server url
// Remove this before launching your app
app.get('/test', function(req, res) {
res.sendFile(path.join(__dirname, '/public/test.html'));
});
var port = process.env.PORT || 1337;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
console.log('parse-server-example running on port ' + port + '.');
});
// This will enable the Live Query real-time server
// ParseServer.createLiveQueryServer(httpServer);
If I run npm install:
Klemens-MBP-2:Cloud klemen$ npm install
npm WARN deprecated mongodb#2.2.10: Please upgrade to 2.2.19 or higher
> bcrypt#1.0.2 install /Users/klemen/Dev/Newcomm/Cloud/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build
node-pre-gyp ERR! Tried to download(404): https://github.com/kelektiv/node.bcrypt.js/releases/download/v1.0.2/bcrypt_lib-v1.0.2-node-v51-darwin-x64.tar.gz
node-pre-gyp ERR! Pre-built binaries not found for bcrypt#1.0.2 and node#7.4.0 (node-v51 ABI) (falling back to source compile with node-gyp)
I have an error with Heroku while i try to submit information on my app.
i'm following steps from the documentation : https://trailhead.salesforce.com/en/project/quickstart-heroku-connect/qs-heroku-connect-4
I run the server, i clic on submit button then on my term i get :
{ [Error: connect ETIMEDOUT 54.228.214.47:5432]
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
address: '54.228.214.47',
port: 5432 }
/home/f.freitag/workspace/radiant-dusk-13720/server.js:17
conn.query(
TypeError: Cannot read property 'query' of null
at /home/f.freitag/workspace/radiant-dusk-13720/server.js:17:13
at /home/f.freitag/workspace/radiant-dusk-13720/node_modules/pg/lib/pool.js:82:27
at /home/f.freitag/workspace/radiant-dusk-13720/node_modules/pg/node_modules/generic-pool/lib/generic-pool.js:339:9
at /home/f.freitag/workspace/radiant-dusk-13720/node_modules/pg/lib/pool.js:31:28
at null.<anonymous> (/home/f.freitag/workspace/radiant-dusk-13720/node_modules/pg/lib/client.js:176:5)
at emitOne (events.js:77:13)
at emit (events.js:169:7)
at Socket.<anonymous> (/home/f.freitag/workspace/radiant-dusk-13720/node_modules/pg/lib/connection.js:59:10)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
npm ERR! Linux 2.6.32-504.12.2.el6.x86_64
npm ERR! argv "/usr/local/node/bin/node" "/usr/local/node/bin/npm" "start"
npm ERR! node v4.5.0
npm ERR! npm v2.15.9
npm ERR! code ELIFECYCLE
npm ERR! phone-change#0.0.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR! Failed at the phone-change#0.0.0 start script 'node server.js'.
npm ERR! This is most likely a problem with the phone-change package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs phone-change
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls phone-change
npm ERR! There is likely additional logging output above.
I tried to see on google for this problem but i found nothing. Also, i'm not a nodeJS programmer, it's maybe simple.
I didn't change code from the git clone.
Here the code from server.js. I put a comment on the line error
var express = require('express');
var bodyParser = require('body-parser');
var pg = require('pg');
var app = express();
app.set('port', process.env.PORT || 5000);
app.use(express.static('public'));
app.use(bodyParser.json());
app.post('/update', function(req, res) {
pg.connect(process.env.DATABASE_URL, function (err, conn, done) {
if (err) console.log(err);
conn.query( //the error
'UPDATE salesforce.Contact SET Phone = $1, HomePhone = $1, MobilePhone = $1 WHERE LOWER(FirstName) = LOWER($2) AND LOWER(LastName) = LOWER($3) AND LOWER(Email) = LOWER($4)',
[req.body.phone.trim(), req.body.firstName.trim(), req.body.lastName.trim(), req.body.email.trim()],
function(err, result) {
done();
if (err) {
res.status(400).json({error: err.message});
}
else {
res.json(result);
}
});
}
else {
done();
res.json(result);
}
}
);
});
app.listen(app.get('port'), function () {
console.log('Express server listening on port ' + app.get('port'));
});
The problem is with the Heroku Connect mappings. Since you've added a new field in the query you also need to update the mappings which you did during the initial setup of Heroku Connect for Contact object.
Steps:
Go to Heroku Connect
Visit mappings section and select the mapping for Contact.
Click on Edit and select HomePhone and save it.
Once above steps are done rerun the application and now should see HomePhone field value populated as same as Phone.