Unable to start the server - node.js

I am trying to use nodemon for auto-starting the server whenever a change is made in the local file, but I get the following error.
(Click image to enlarge)
package.json
{
"name": "myapp",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "if [[ $NODE_ENV == 'production' ]]; then node ./bin/www; else nodemon ./bin/www; fi"
},
"dependencies": {
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"express": "~4.16.0",
"http-errors": "~1.6.2",
"morgan": "~1.9.0",
"pug": "^2.0.3"
},
"devDependencies": {
"nodemon": "^1.18.10"
}
}

It looks like the start script uses Bash scripting syntax, but the screenshot is of a Windows command terminal. The error is because Windows doesn't understand the Bash syntax.
To immediately get you running, you can just change the start script to just nodemon ./bin/www. You'll then want to either figure out the correct syntax, or add another script for the production start script, like "start-prod": "node ./bin/www"' and runnpm run start-prod` in production.

Related

NPM version discrepancy between main version and cpanel version

When running npm-version on my local server/laptop I receive 7.5.6
However, when running on cpanel terminal -- I receive
[~]# /opt/cpanel/ea-nodejs10/bin/npm --version
6.14.11
And this 6.14.11 is after I ran
[~]# /opt/cpanel/ea-nodejs10/bin/npm install --latest version -g
Which I thought would update it to the 7.5.6 as I used the same command to update the one on my computer as well.
In all I'm having trouble deploying my webapp on bluehost via cpanel. Even though the app is registered with the application manager -- and the Ensure Dependencies part came out done and successful. And the git repo is cloned and deployed with no errors.
Would this discrepancy be causing the app not to launch?
I can't understand why it isn't deploying properly, so I was thinking there may be something with the package.json or (package-lock.json) -- ei - could the versions in such bet preventing deployment due to discrepancies.
Would love some help, been trying to get this deployed for days!
my package.json
{
"name": "vandenbergdevelopment",
"version": "1.0.0",
"description": "DeltaDesignServer",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js"
},
"author": "J Vandenberg",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"ejs": "^3.1.6",
"express": "^4.17.1",
"firebase-tools": "^9.5.0",
"hover.css": "^2.3.2",
"nodemailer": "^6.4.18",
"nodemailer-mailgun-transport": "^2.0.2",
"version": "^0.0.4"
}
}
The top bit to the lock.json
"": {
"name": "vandenbergdevelopment",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"version": "^0.0.4",
"body-parser": "^1.19.0",
"ejs": "^3.1.6",
"express": "^4.17.1",
"firebase-tools": "^9.5.0",
"hover.css": "^2.3.2",
"nodemailer": "^6.4.18",
"nodemailer-mailgun-transport": "^2.0.2"
}
},
Thank you!

'MONGO_USER' is not recognized as an internal or external command, operable program or batch file

I'm following NodeJS Tutorial on Udemy
I got the error when I tried this code
{
"name": "nodejs-complete-guide",
"version": "1.0.0",
"description": "Complete Node.js Guide",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "MONGO_USER=MonkeyKing MONGO_PASSWORD=loveguitar4ever MONGO_DEFAULT_DATABASE=message STRIPE_KEY=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 node app.js",
"start-server": "node app.js",
"start:dev": "nodemon app.js"
},
"author": "MonkeyKing",
"license": "ISC",
"devDependencies": {
"nodemon": "^1.18.3"
},
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.3",
"connect-flash": "^0.1.1",
"connect-mongodb-session": "^2.0.3",
"csurf": "^1.9.0",
"ejs": "^2.6.1",
"express": "^4.16.3",
"express-handlebars": "^3.0.0",
"express-session": "^1.15.6",
"express-validator": "^5.3.0",
"mongodb": "^3.1.6",
"mongoose": "^5.2.17",
"multer": "^1.4.0",
"mysql2": "^1.6.1",
"nodemailer": "^4.6.8",
"nodemailer-sendgrid-transport": "^0.2.0",
"pdfkit": "^0.8.3",
"pug": "^2.0.3",
"sequelize": "^5.0.0-beta.11",
"stripe": "^6.12.1"
}
}
the error is:
'MONGO_USER' is not recognized as an internal or external command,
operable program or batch file.
sk_live_51GekpQCukpHeumjmDZhZiXzC5F6SaltbPDxQGLPE9sswmFWknSZL87m1a7ktjnpm ERR!
npm ERR! Failed at the nodejs-complete-guide#1.0.0 start script. GO_PASSWORD=loveguitar4ever MONGO_DE
npm ERR! This is probably not a problem with npm. There is likely addiSaltbPDxQGLPE9sswmFWknSZL87m1a7ktjImtional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\MonkeyKing\AppData\Roaming\npm-cache\_logs\2020-07-19T01_23_24_946Z-debug.log
Run your code from a UNIX-like shell, not from Windows' cmd.exe. The syntax of prefixing a command with variable assignments is not understood by cmd.
Use the Git Bash for example. I assume you already have Git installed (if not, I bet you will have to do that very soon anyway).
To get an even more Linux-y environment, I'd suggest using WSL (Windows Subsystem for Linux) for web development in the first place, though.
For this specific case: You could also remove the variable assignments from the start script and run them manually before starting the app, using set MONGO_USER=MonkeyKing etc., and remember doing that every time that you open a new shell (possibly creating a batch file). Alternatively move it into a .env file and use the dotenv package to load it.

Build node.js app using yarn but getting error Command "build" not found

This is my package.json file.
{
"name": "moneymall",
"version": "1.0.0",
"description": "A money mall server app.",
"main": "index.js",
"author": "Anbu Selvan",
"license": "ISC",
"keywords": [],
"dependencies": {
"body-parser": "^1.18.3",
"cors": "^2.8.5",
"e": "0.0.4",
"express": "^4.16.4",
"mysql": "^2.16.0",
"pug": "^2.0.3",
"yarn": "^1.15.2"
},
"devDependencies": {
"nodemon": "^1.18.10",
"react-scripts": "^2.1.8"
}
}
Run yarn build and get this error.
yarn run v1.15.2 error Command "build" not found. info Visit
https://yarnpkg.com/en/docs/cli/run for documentation about this
command
You don't seem to have a script.build key defined in your package.json file. Sample entry for building with webpack library would be:
"scripts": {
"build": "webpack"
}
If you execute yarn run it will show the list of commands which can be run.
Ideally yarn run dev will do the trick of compiling the build
Please re-read the yarn documentation. You don't seem to have a script key declaring what you build script is, and thus Yarn does not know what to load.

Npm ‘Dev’ Watchify/Browserify/vueify cmd to compile Vue component and start Express server fails? (server fails to start)

I’m following a tutorial https://mindthecode.com/using-vue-components-in-your-express-app/ to use vue components with Express.
Part of that is configuring an npm dev script to compile the vue component with Browserify/vueify, start Watchify, then start the Express Server.
Every step of the turorial worked but the ‘dev’ script doesn't work 100% as the express server doesn't start.
Can anyone help figure how what is wrong or what I need to do to get that script working?
Package.json
"scripts": {
"start": "echo 'server starting on port 3000' & node ./bin/www",
"dev": "watchify -vd -p browserify-hmr -t vueify -e public/javascripts/main.js -o public/javascripts/bundle.js & node ./bin/www"
},
‘npm run dev’ compiles the vue component and starts watchify and the hot reload works if I change the vue component code. HOWEVER, the express server fails to start?
Note:
browserify -t vueify -e public/javascripts/main.js -o public/javascripts/bundle.js – works fine at the command line to compile the .vue files
npm start – works fine and can load page at ‘localhost:3000’
I'm using windows10, node v8.9.4 and some of the relevant dependencies from package.json
"browserify-hmr": "^0.3.5",
"express": "~4.14.0",
"vue": "^2.5.0",
"vueify": "^9.4.1",
"watchify": "^3.9.0"
You can see completed package.json and full repo from this tutorial
https://github.com/Hyra/vue-components-in-express/blob/master/package.json
{
"name": "vue-components-in-express",
"version": "0.0.1",
"private": false,
"description": "Sample code to support blog post 'Using Vue Components in your Express app' at https://mindthecode.com/using-vue-components-in-your-express-app/",
"author": "Stef van den Ham <stef#mindthecode.com>",
"scripts": {
"start": "node ./bin/www",
"dev": "watchify -vd -p browserify-hmr -t vueify -e public/javascripts/main.js -o public/javascripts/bundle.js & node ./bin/www"
},
"dependencies": {
"body-parser": "~1.15.2",
"browserify-hmr": "^0.3.5",
"cookie-parser": "~1.4.3",
"debug": "~2.2.0",
"express": "~4.14.0",
"morgan": "~1.7.0",
"node-sass": "^4.5.3",
"pug": "~2.0.0-beta6",
"serve-favicon": "~2.3.0",
"vue": "^2.5.0",
"vueify": "^9.4.1",
"watchify": "^3.9.0"
}
}

How to make Node Webkit work with express generator

im trying to make an App with Node and Express using express generator and packing everything with node-webkit. express generator creates an extremely basic app , but it works running npm start on localhost:30000.
the manifest
{
"name": "app",
"version": "0.0.0",
"private": true,
"node-main": "./app.js",
"main": "http://localhost:8080",
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.15.1",
"bower": "^1.7.9",
"cookie-parser": "~1.4.3",
"debug": "~2.2.0",
"express": "~4.13.4",
"morgan": "~1.7.0",
"pug": "^2.0.0-beta4",
"serve-favicon": "~2.3.0"
}
}
the folder structure
When i run the app with nwjs the window displays that the page can not be loaded, but the console doesn't show any error. I tried changing
"main": "http://localhost:8080" to "main": "http://localhost:3000"
which is how the app runs usually, but it didnt work either.
is this possible?
what am i missing?
thanks in advance
This can be a bit late, but anyway.
Here is the source: https://github.com/nwjs/nw.js/wiki/NW.js-use-express-and-similar-web-frameworks
node-main should have path to file, which sets up the server. In this case I assume it is located in bin directory and is named www. Therefore, the package.json should be like:
{
...
"node-main": "./bin/www",
"main": "http://localhost:3000",
...
}
Also check the port number if it is 3000 or something else.

Resources