what is the idiomatic way to run a Node.js project that has package.json with '"main": "index.js"' inside? do I run something like "node run" or "npm run" ?
The package.json file:
{
"name": "bandymas",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
And index.js file exists. So what is the idiomatic way?
You can add a start script to your package.json:
{
"name": "bandymas",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"keywords": [],
"author": "",
"license": "ISC"
}
This way, you can start your project by just running npm start.
Related
I am trying to deploy a bot to run on Heroku servers. It fails to compile the app when I try to commit. Here is my package.json
{
"name": "Bot",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node bot.js"
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"discord.js": "^12.0.2",
"dotenv": "^8.2.0"
}
}
bot.js is the correct name for the bot configuration file. It works fine when I take out start: node bot.js but the bot doesn't come online of course.
Try Changing main to bot.js.
https://devcenter.heroku.com/articles/deploying-nodejs
I am trying to run my node server as a background process using forever. When I close the putty terminal the server still shuts down. What am I doing worng?
command: forever -c "npm start &" ./
package.json
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon ./bin/www",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
.....
}
}
I added serve keyword inside package.json with localhost:8080 as it's value but it wont work. I tried using localhost ip address instead of "localhost" still got error.
On my package.json
{
"name": "package-lock",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"framework7": "^3.0.1"
},
"devDependencies": {},
"scripts": {
"serve":"localhost:8080",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
I am using a simple npm module http-server https://www.npmjs.com/package/http-server to server static website.
This is my package json
{
"name": "dashboard-ng-starfleet",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start":"./node_modules/http-server/bin/http-server -p=8080"
},
"repository": {
"type": "git",
"url": ""
},
"author": "",
"license": "ISC",
"homepage": "",
"devDependencies": {
"http-server": "^0.10.0"
}
}
Server starts once but once i stop it using Ctrl+C in terminal and again start server, it says Address already in use.
Ideally it should have stopped.
Any help ?
Your start script should be
"start":"./node_modules/http-server/bin/http-server -p 8080"
i am using http-server https://www.npmjs.com/package/http-server
I am using src folder as the path.
But the server is starting directly at Project folder listing the directories.
How can i server src folder.
My folder structure is
Project
package.json
src
index.html
And this is my package.json
{
"name": "dashboard-ng-starfleet",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "http-server ./src -o -p 9000"
},
"repository": {
"type": "git",
"url": ""
},
"author": "",
"license": "ISC",
"homepage": "",
"devDependencies": {
"http-server": "^0.10.0"
}
}