'npm start' in node.js doesn't works - node.js

node App.js works, but npm start doesn't works.
I just followed this nodejs tutorial (tutorial is written by Korean).
I tried to change code to:
"scripts": {
"start": "webpack-dev-server"
}
but it didn't work.
this is my code:
App.js
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
package.json
{
"name": "codlab-nodejs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node js"
},
"author": "",
"license": "ISC"
}
package-lock.json
{
"name": "codlab-nodejs",
"version": "1.0.0",
"lockfileVersion": 1
}
This is the err msg.
C:\Users\김동희\codlab-nodejs>npm start
> codlab-nodejs#1.0.0 start C:\Users\김동희\codlab-nodejs
> node js
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'C:\Users\김동희\codlab-nodejs\js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! codlab-nodejs#1.0.0 start: `node js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the codlab-nodejs#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\김동희\AppData\Roaming\npm-cache\_logs\2019-08-03T14_03_42_211Z-debug.log

In your package.json change the value of the property "start".
Replace:
"start": "node js"
With:
"start": "node App.js"

The start npm script is trying to run a file called js, which does not exist and consequently fails.
Instead, set your start npm script to be the correct command that asks Node.js to run your App.js file.
Your package.json would include something like this:
"scripts": {
"start": "node App.js"
}

Related

npm ELIFECYCLE error with npm run start-server

I'm getting npm ERR! code ELIFECYCLE when I try to run my server command
What I'm trying to do is
TensorFlow.js Training in Node.js
It's for college, step 3 says to try out the server I get this
package.json snip
"scripts": {
"start-client": "webpack && webpack-dev-server",
"start-server": "node server.js"
},
error message
C:\xampp\htdocs\leo\baseball>npm run start-server
> tfjs-examples-baseball-node#0.2.0 start-server C:\xampp\htdocs\leo\baseball
> node server.js
internal/modules/cjs/loader.js:1122
return process.dlopen(module, path.toNamespacedPath(filename));
^
Error: Não foi possível encontrar o módulo especificado.
\\?\C:\xampp\htdocs\leo\baseball\node_modules\#tensorflow\tfjs-node\lib\napi-v5\tfjs_binding.node
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1122:18)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (C:\xampp\htdocs\leo\baseball\node_modules\#tensorflow\tfjs-node\dist\index.js:58:16)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! tfjs-examples-baseball-node#0.2.0 start-server: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the tfjs-examples-baseball-node#0.2.0 start-server 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! C:\Users\Usuário\AppData\Roaming\npm-cache\_logs\2020-12-11T07_01_54_120Z-debug.log
server.js
require('#tensorflow/tfjs-node');
const http = require('http');
const socketio = require('socket.io');
const pitch_type = require('./pitch_type');
const TIMEOUT_BETWEEN_EPOCHS_MS = 500;
const PORT = 8001;
// util function to sleep for a given ms
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// Main function to start server, perform model training, and emit stats via the socket connection
async function run() {
const port = process.env.PORT || PORT;
const server = http.createServer();
const io = socketio(server);
server.listen(port, () => {
console.log(` > Running socket on port: ${port}`);
});
io.on('connection', (socket) => {
socket.on('predictSample', async (sample) => {
io.emit('predictResult', await pitch_type.predictSample(sample));
});
});
let numTrainingIterations = 10;
for (var i = 0; i < numTrainingIterations; i++) {
console.log(`Training iteration : ${i+1} / ${numTrainingIterations}`);
await pitch_type.model.fitDataset(pitch_type.trainingData, {epochs: 1});
console.log('accuracyPerClass', await pitch_type.evaluate(true));
await sleep(TIMEOUT_BETWEEN_EPOCHS_MS);
}
io.emit('trainingComplete', true);
}
run();
I already tried:
cache clean --force/-f, delete node_modules package-lock.json run npm install
removing package-lock.json and running the server
npm install -g node-pre-gyp
npm install --unsafe-perm
Changing the port from 8001 to 10000 3000 80
running it with every single thing else on my computer closed (this includes my xampp on the bg)
some info
node -v 14.15.1
npm -v 6.14.8
windows 10 x64
My grade needs me to overcome this and finish the tutorial
line 13 of my error accused something wrong at line 58 at this file
at Object.<anonymous> (C:\xampp\htdocs\leo\baseball\node_modules\#tensorflow\tfjs-node\dist\index.js:58:16)
opened the file and commented the line, code ran without problems

Babel-node not found - Heroku Deploy

I am trying to deploy a simple Ecommerce website that has Reactjs , Node, Express and MongoDB. I have followed a tutorial to deploy it to the heroku. I have used babel but in the tutorial, it wasn't used. I know we don't use babel for production and used only for the development purpose, but I am not sure how I would still deploy my website.
The server is working perfectly locally and also the Heroku build is successful. But when I visit my deployed app on heroku it says application error.
Here are the logs from Heroku:
2020-06-29T16:04:44.812179+00:00 heroku[web.1]: Starting process with command `npm start`
2020-06-29T16:04:48.072669+00:00 app[web.1]:
2020-06-29T16:04:48.072690+00:00 app[web.1]: > e-commerce-site#1.0.0 start /app
2020-06-29T16:04:48.072691+00:00 app[web.1]: > babel-node backend/server.js
2020-06-29T16:04:48.072691+00:00 app[web.1]:
2020-06-29T16:04:48.105827+00:00 app[web.1]: sh: 1: babel-node: not found
2020-06-29T16:04:48.110266+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-06-29T16:04:48.111030+00:00 app[web.1]: npm ERR! syscall spawn
2020-06-29T16:04:48.111915+00:00 app[web.1]: npm ERR! file sh
2020-06-29T16:04:48.112482+00:00 app[web.1]: npm ERR! errno ENOENT
2020-06-29T16:04:48.114018+00:00 app[web.1]: npm ERR! e-commerce-site#1.0.0 start: `babel-node backend/server.js`
2020-06-29T16:04:48.114155+00:00 app[web.1]: npm ERR! spawn ENOENT
2020-06-29T16:04:48.114342+00:00 app[web.1]: npm ERR!
2020-06-29T16:04:48.114508+00:00 app[web.1]: npm ERR! Failed at the e-commerce-site#1.0.0 start script.
2020-06-29T16:04:48.114601+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-06-29T16:04:48.133545+00:00 app[web.1]:
2020-06-29T16:04:48.134148+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-06-29T16:04:48.134771+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-06-
29T16_04_48_124Z-debug.log
2020-06-29T16:04:48.213867+00:00 heroku[web.1]: Process exited with status 1
2020-06-29T16:04:48.265610+00:00 heroku[web.1]: State changed from starting to crashed
2020-06-29T16:04:48.268292+00:00 heroku[web.1]: State changed from crashed to starting
2020-06-29T16:04:57.328678+00:00 heroku[web.1]: Starting process with command `npm start`
2020-06-29T16:05:00.299582+00:00 app[web.1]:
2020-06-29T16:05:00.299595+00:00 app[web.1]: > e-commerce-site#1.0.0 start /app
2020-06-29T16:05:00.299595+00:00 app[web.1]: > babel-node backend/server.js
2020-06-29T16:05:00.299596+00:00 app[web.1]:
2020-06-29T16:05:00.308802+00:00 app[web.1]: sh: 1: babel-node: not found
2020-06-29T16:05:00.312668+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-06-29T16:05:00.313206+00:00 app[web.1]: npm ERR! syscall spawn
2020-06-29T16:05:00.313637+00:00 app[web.1]: npm ERR! file sh
2020-06-29T16:05:00.314093+00:00 app[web.1]: npm ERR! errno ENOENT
2020-06-29T16:05:00.315953+00:00 app[web.1]: npm ERR! e-commerce-site#1.0.0 start: `babel-node backend/server.js`
2020-06-29T16:05:00.316283+00:00 app[web.1]: npm ERR! spawn ENOENT
2020-06-29T16:05:00.316613+00:00 app[web.1]: npm ERR!
2020-06-29T16:05:00.316974+00:00 app[web.1]: npm ERR! Failed at the e-commerce-site#1.0.0 start script.
2020-06-29T16:05:00.317312+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-06-29T16:05:00.344371+00:00 app[web.1]:
2020-06-29T16:05:00.344828+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-06-29T16:05:00.345202+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-06-29T16_05_00_319Z-debug.log
2020-06-29T16:05:00.406294+00:00 heroku[web.1]: Process exited with status 1
2020-06-29T16:05:00.466244+00:00 heroku[web.1]: State changed from starting to crashed
File Name: Server.js
The file where I have all the connections for MongoDB:
import express from "express";
import data from "./data";
import dotenv from "dotenv";
import config from "./config";
import mongoose from "mongoose";
import userRoute from "./routes/userRoute";
import productRoute from "./routes/productRoute";
import bodyParser from "body-parser";
dotenv.config();
const mongodbUrl = config.MONGODB_URL;
const PORT = process.env.PORT || 5000;
mongoose.connect(mongodbUrl , {
useNewUrlParser : true,
useUnifiedTopology: true,
useCreateIndex: true
}).catch(error => console.log(error.reason));
const app = express();
app.use(bodyParser.json());
app.use("/api/users" , userRoute);
app.use("/api/products" , productRoute);
if (process.env.NODE_ENV === "production"){
app.use(express.static("./frontend/build"));
}
app.listen(PORT , console.log(`Server started at ${PORT}`));
File Name: config.js
export default{
MONGODB_URL: process.env.MONGODB_URL || "mongodb://localhost/ecommercesite",
JWT_SECRET: process.env.JWT_SECRET || "somethingsecret"
}
File Name: Package.json
{
"name": "e-commerce-site",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build" : "cd frontend && npm run build",
"install-client" : "cd frontend && npm install",
"heroku-postbuild" : "npm run install-client && npm run build",
"start": "babel-node backend/server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.19.2",
"body-parser": "^1.19.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.9.16"
},
"devDependencies": {
"#babel/cli": "^7.10.1",
"#babel/core": "^7.10.1",
"#babel/node": "^7.10.1",
"#babel/preset-env": "^7.10.1",
"nodemon": "^2.0.4"
}
}

Problem with React/Node.js app deployment on Heroku

I have problem with deployment of my 'TODO APP' on Heroku. I read multiple articles, tutorials and answers on Stack Overflow, but it still doesn't resolve my problem.
This is my index.js file in root directory:
const express = require('express')
const apiRoute = require('./routes/api/index')
const bodyParser = require('body-parser')
const app = express()
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({
extended: true
}))
app.use('/api', apiRoute)
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'))
const path = require('path')
app.get('*', function(req, res) {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'))
})
}
const PORT = process.env.PORT || 8000
app.listen(PORT)
In the code below you can see scripts in package.json for root directory:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"client": "npm run start --prefix client",
"server": "nodemon index.js",
"dev": "concurrently --kill-others-on-fail \"npm run server\" \"npm run client\"",
"start": "node index.js",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
},
In the heroku logs I can see, that "concurrently is not found:
2020-05-18T19:00:50.438389+00:00 app[web.1]: sh: 1: concurrently: not found
2020-05-18T19:00:50.443535+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-05-18T19:00:50.444083+00:00 app[web.1]: npm ERR! syscall spawn
2020-05-18T19:00:50.444495+00:00 app[web.1]: npm ERR! file sh
2020-05-18T19:00:50.444972+00:00 app[web.1]: npm ERR! errno ENOENT
2020-05-18T19:00:50.446708+00:00 app[web.1]: npm ERR! to-do-app#1.0.0 start: `concurrently "npm run server" "npm run client"`
2020-05-18T19:00:50.446990+00:00 app[web.1]: npm ERR! spawn ENOENT
I have tried multiple things, but none of them work. Any ideas please?
In your package.json maybe the script dev is causing an issue.
Try clearing all the scripts and only leave
"start" : "node server.js"
"test": "echo "Error: no test specified" && exit 1"
"heroku-postbuild": "cd client && npm install && npm run build"

My node + express app deploys fine locally but will not deploy when pushed to heroku

first off my apologies if this is a basic solve. I'm new to Node + Express and still trying to grapple a few concepts!
I have a Node + Express app that starts locally but when I push to heroku or run heroku local web it exits with code 0 and produces no error code for me to diagnose.
Here is the specific output from the logs when I deploy to Heroku:
2018-06-30T11:58:37.052754+00:00 heroku[web.1]: Starting process with command `npm run build`
2018-06-30T11:58:39.336703+00:00 app[web.1]:
2018-06-30T11:58:39.336728+00:00 app[web.1]: > bookworm-api#1.0.0 build /app
2018-06-30T11:58:39.336733+00:00 app[web.1]: > npm run clean && npm run build-babel
2018-06-30T11:58:39.336734+00:00 app[web.1]:
2018-06-30T11:58:39.777160+00:00 app[web.1]:
2018-06-30T11:58:39.777199+00:00 app[web.1]: > bookworm-api#1.0.0 clean /app
2018-06-30T11:58:39.777201+00:00 app[web.1]: > rm -rf build && mkdir build
2018-06-30T11:58:39.777202+00:00 app[web.1]:
2018-06-30T11:58:40.305583+00:00 app[web.1]:
2018-06-30T11:58:40.305603+00:00 app[web.1]: > bookworm-api#1.0.0 build-babel /app
2018-06-30T11:58:40.305605+00:00 app[web.1]: > babel -d ./build ./src -s
2018-06-30T11:58:40.305610+00:00 app[web.1]:
2018-06-30T11:58:41.146122+00:00 app[web.1]: src/index.js -> build/index.js
2018-06-30T11:58:41.196474+00:00 app[web.1]: src/mailer.js -> build/mailer.js
2018-06-30T11:58:41.242714+00:00 app[web.1]: src/models/Circuit.js -> build/models/Circuit.js
2018-06-30T11:58:41.293304+00:00 app[web.1]: src/models/User.js -> build/models/User.js
2018-06-30T11:58:41.346985+00:00 app[web.1]: src/routes/auth.js -> build/routes/auth.js
2018-06-30T11:58:41.362022+00:00 app[web.1]: src/routes/circuits.js -> build/routes/circuits.js
2018-06-30T11:58:41.380720+00:00 app[web.1]: src/routes/stripe.js -> build/routes/stripe.js
2018-06-30T11:58:41.411474+00:00 app[web.1]: src/routes/users.js -> build/routes/users.js
2018-06-30T11:58:41.423692+00:00 app[web.1]: src/utils/parseErrors.js -> build/utils/parseErrors.js
2018-06-30T11:58:41.508066+00:00 heroku[web.1]: Process exited with status 0
2018-06-30T11:58:41.532442+00:00 heroku[web.1]: State changed from starting to crashed
Here is the output when I run Heroku local web
[OKAY] Loaded ENV .env File as KEY=VALUE Format
8:04:38 AM web.1 | > bookworm-api#1.0.0 build /Users/kylependergast/Desktop/projects/bookworm/bookworm-api
8:04:38 AM web.1 | > npm run clean && npm run build-babel
8:04:38 AM web.1 | > bookworm-api#1.0.0 clean /Users/kylependergast/Desktop/projects/bookworm/bookworm-api
8:04:38 AM web.1 | > rm -rf build && mkdir build
8:04:39 AM web.1 | > bookworm-api#1.0.0 build-babel /Users/kylependergast/Desktop/projects/bookworm/bookworm-api
8:04:39 AM web.1 | > babel -d ./build ./src -s
8:04:39 AM web.1 | src/index.js -> build/index.js
8:04:39 AM web.1 | src/mailer.js -> build/mailer.js
8:04:39 AM web.1 | src/models/Circuit.js -> build/models/Circuit.js
8:04:39 AM web.1 | src/models/User.js -> build/models/User.js
8:04:39 AM web.1 | src/routes/auth.js -> build/routes/auth.js
8:04:39 AM web.1 | src/routes/circuits.js -> build/routes/circuits.js
8:04:39 AM web.1 | src/routes/stripe.js -> build/routes/stripe.js
8:04:39 AM web.1 | src/routes/users.js -> build/routes/users.js
8:04:39 AM web.1 | src/utils/parseErrors.js -> build/utils/parseErrors.js
8:04:39 AM web.1 Exited Successfully
Here is my package.json file:
{
"name": "bookworm-api",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"test": "nodemon --exec babel-node -- src/index.js",
"clean": "rm -rf build && mkdir build",
"build-babel": "babel -d ./build ./src -s",
"build": "npm run clean && npm run build-babel",
"start": "npm run build && node ./build/index.js"
},
"engines": {
"node": "9.4.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-eslint": "^8.2.3",
"babel-preset-env": "^1.7.0",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-prettier": "^2.6.0",
"nodemon": "^1.17.4"
},
"dependencies": {
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"bcrypt": "^2.0.1",
"bluebird": "^3.5.1",
"body-parser": "^1.18.2",
"dotenv": "^5.0.1",
"express": "^4.16.3",
"jsonwebtoken": "^8.2.1",
"lodash": "^4.17.10",
"mongodb": "^3.1.0",
"mongoose": "^4.11.10",
"mongoose-unique-validator": "^2.0.1",
"nodemailer": "^4.6.4",
"request-promise": "^4.2.2",
"stripe": "^6.1.1",
"uuid": "^3.2.1",
"xml2js": "^0.4.19"
}
}
And here is my index.js file:
import express from 'express';
import path from 'path';
import mongoose from 'mongoose';
import bodyParser from 'body-parser';
import dotenv from 'dotenv';
import Promise from 'bluebird';
import auth from './routes/auth';
import users from './routes/users';
import circuits from "./routes/circuits";
import stripe from './routes/stripe';
dotenv.config();
const app = express();
app.use(bodyParser.json());
mongoose.Promise = Promise;
mongoose.connect(
process.env.MONGODB_URI || process.env.MONGODB_URL_DEV_LOCAL,
{useMongoClient: true});
app.use('/api/auth', auth);
app.use('/api/users', users);
app.use('/api/circuits', circuits);
app.use('/api/stripe', stripe);
app.post('/api/auth', (req, res) => {
res.status(400).json({ errors: {global: "Invalid Credentials" } });
});
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
})
var port = process.env.PORT || 8080
app.listen(port || 8080, function(){
console.log("App is running on port " + port);
});
Here is my Procfile
web: npm run build
I'm sure someone else has run into this issue but I've been unable to find resources that suggest what next steps to take. If you can point me to a relevant resource or provide the answer yourself it would be very much appreciated!
Your Procfile seems to be defined such that you're building stuff when starting the process. The build succeeds (returns 0), but then the process stops, which Heroku thinks is a bad condition, cause web servers shouldn't stop.
You need to actually run the web server in Heroku. Something like web: npm run start.
Though I would separate the build & run stages. You should do the build locally, or on a build machine (or a build service, such as Travis, Circle etc - they have Heroku integrations as well), and then push something compiled to Heroku. So Procfile could only be web: node ./build/index.js or something like that.

Stopping Heroku from running npm start + what to run instead?

Disclaimer: I'm a node.js/grunt/bower newbie.
I have a node.js/grunt/bower application that I'm trying to deploy on Heroku. Heroku builds the application as expected, but then it tries to run "npm start" which I did not specify in the package.json file. This command fails, I'm guessing because it is not a server application, and I can not see the actual application deployed in it's place on Heroku. My application can be found here: https://github.com/uzilan/sufusku
So - how do I get Heroku not to run the "npm start" command, and what should it run instead? After running grunt build, the application is available on the dist folder.
package.json:
{
"name": "sufusku",
"version": "0.0.1",
"description": "Sufusku - makes your annoying sudoku easier",
"repository": {
"type": "git",
"url": "git://github.com/uzilan/sufusku.git"
},
"license": "(MIT OR Apache-2.0)",
"dependencies": {
"bower": "^1.4.1",
"grunt": "0.4.5",
"grunt-cli": "0.1.13",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-connect": "^0.11.2",
"grunt-contrib-copy": "^0.8.0",
"grunt-contrib-cssmin": "^0.13.0",
"grunt-contrib-htmlmin": "^0.4.0",
"grunt-contrib-uglify": "^0.9.1",
"grunt-contrib-watch": "^0.6.1",
"grunt-ng-annotate": "^1.0.1",
"load-grunt-config": "^0.17.2",
"time-grunt": "^1.2.1"
},
"devDependencies": {},
"engines": {
"node": ">=0.8.0"
},
"scripts": {
"postinstall": "./node_modules/bower/bin/bower install && grunt build"
}
}
Gruntfile.js:
module.exports = function (grunt) {
var appname = require('./package.json').name;
require('load-grunt-config')(grunt, {
data: {
dist: 'dist/' + appname,
app: 'src',
distscripts: 'dist/' + appname + '/scripts',
diststyles: 'dist/' + appname + '/styles',
disthtml: 'dist/' + appname,
disttest: 'dist/' + appname + '/test',
appstyles: 'src/css'
}
});
require('time-grunt')(grunt);
grunt.registerTask('build', ['clean:dist', 'ngAnnotate:application', 'uglify', 'htmlmin', 'cssmin', 'copy:serve', 'concat:components']);
grunt.registerTask('serve', ['build', 'connect:livereload', 'watch']);
grunt.registerTask('default', function () {
grunt.task.run(['build']);
});
};
Heroku log:
...
heroku[web.1]: Starting process with command `npm start`
app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
app[web.1]: npm ERR! Linux 3.13.0-57-generic
app[web.1]: npm ERR! npm v2.11.3
app[web.1]: npm ERR! missing script: start
app[web.1]: npm ERR! Please include the following file with any support request:
app[web.1]: npm ERR!
app[web.1]: npm ERR! node v0.12.7
app[web.1]:
app[web.1]: npm ERR! /app/npm-debug.log
app[web.1]: npm ERR! If you need help, you may report this error at:
app[web.1]:
app[web.1]: npm ERR! <https://github.com/npm/npm/issues>
heroku[web.1]: Process exited with status 1
heroku[web.1]: State changed from starting to crashed
heroku[web.1]: State changed from crashed to starting
heroku[web.1]: Starting process with command `npm start`
app[web.1]: npm ERR! Linux 3.13.0-57-generic
app[web.1]: npm ERR! node v0.12.7
app[web.1]:
app[web.1]: npm ERR! missing script: start
...
npm start is the default web process run when no other process has been specified in a Procfile. Since you say you don't want a server (a web process), the first thing to do is to scale the default process to zero:
heroku scale web=0
Next, you'll want to tell Heroku what process you want to run instead of web by adding its process types to a file called Procfile. For instance, if your app starts with node foobar.js, you could create a Procfile that looks like:
bot: node foobar.js
Then scale the 'bot' process up to at least one:
heroku scale bot=1
Looking at your code above, even though you say it isn't a server-based application, it looks very much like a server-based application. How do you start your app locally? Whatever the answer that should probably go into the Procfile, which you can learn more about here:
https://devcenter.heroku.com/articles/procfile
disclosure: I'm the Node.js platform owner at Heroku
Thanks for the answer. After trying the tutorial mentioned above and looking at the solutions in node.js TypeError: path must be absolute or specify root to res.sendFile [failed to parse JSON] I ended up writing a server.js file which solved the problem. And it looks like this:
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
});
app.get(/^(.+)$/, function (req, res) {
res.sendFile(__dirname + req.params[0]);
});
var PORT = process.env.PORT || 3000;
app.listen(PORT);

Resources