npm ERR! Missing script: "dev" - node.js

I am trying to create a Dapp using truffle but when I reach the stage of using the command npm run dev it gives me an error saying MISSING SCRIP. my code is as follows:
{
"name": "eth-vreg",
"version": "1.0.0",
"description": "Blockchain vreg Powered By Ethereum",
"main": "truffle-config.js",
"directories": {
"test": "test"
},
"scripts": {
"dev": "lite-server",
"test": "echo \"Error: no test specified\" && sexit 1"
},

You need to specify the command to run when executing npm run. in this case node
"scripts": {
"dev": "node lite-server",
"test": "echo \"Error: no test specified\" && sexit 1"
}
You can read more about the scripts property here.

Related

Failed npm run dev with Tailwindcss

I just follow instruction from this youtube video https://youtu.be/lhCGoQkya5Q but i cant running npm run dev
in terminal:
PS C:\Users\Turtle\Desktop\My Site> npm run dev
npm ERR! Missing script: "dev"
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Turtle\AppData\Local\npm-cache\_logs\2022-02-22T19_13_01_984Z-debug-0.log
Project\css\tailwind.css
#tailwind base;
#tailwind components;
#tailwind utilities;
package.json
{
"name": "my-site",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"autoprefixer": "^10.4.2",
"postcss": "^8.4.6",
"tailwindcss": "^3.0.23",
"vite": "^2.8.4"
}
}
You have to add a new key in your scripts key
"scripts": {
"dev": "npx tailwindcss -i ./css/tailwind.css -o ./dist/style.css --watch",
"test": "echo \"Error: no test specified\" && exit 1"
},
./css/tailwind.css is your sour; change the name according.ly
./dist/style.css is your dist path/filename
--watch is to keep running and watch when you change something in your code

How to read ignored filename from config.json file

I have a config file that I specify my database path in that:
{
"runningPort": 3001,
"databasePath":"database.json",
}
The problem is that I use Nodemon and I want to ignore my database file when using it.
my script in package.json is Like this:
{
...,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon --ignore database.json start.js"
},
...
}
what I want is to read database.json from config.json file so that just by changing databasePath in config.json file I can change the targeted database.

npm link is not working, bash: dosmth: command not found

I am trying to do basic CLI with node, but seems like it is not linking from/to correct directory.
I have file named create, which contains command: console.log(process.cwd());
When I run in bash node create, it gives me that outcome:
/Users/katya/Desktop/code/drawer.
However, after running npm link (or sudo npm link), it prints that:
/Users/katya/.npm-packages/bin/dosmth -> /Users/katya/.npm-packages/lib/node_modules/drawer/create
/Users/katya/.npm-packages/lib/node_modules/drawer -> /Users/katya/Desktop/code/drawer
and after that if I run dosmth in bash I get:
bash: dosmth: command not found
I assume there is something to do with ./npm-packages/ appearing in the path.
I tried to delete node completely from computer and install again but did not help.
If you have any idea I would really appreciate your help.
My package.json:
{
"name": "drawer",
"version": "1.0.0",
"description": "",
"main": "index.js",
"bin": {
"dosmth": "create"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
Have you tried changing bin to point to your index.js?
{
// Other keys ...
"bin": {
"dosmth": "./index.js"
},
//...
}

How to pass params to node scripts from command line?

*package.json**
{
"name": "test-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "node build build_name"
},
"author": "",
"license": "ISC",
"devDependencies": {
}
}
build.js
console.log("Building Code. Output File Name:", process.env.build_name);
Command Line
$ npm run build build_name="web"
I want to pass a parameter build_name from the command line while executing build script. I will use that param inside my build script. Can someone tell me how to achieve this? Also if I did not pass build_name from the command line, can we send a default value from here "build": "node build build_name" instead of build_name.
Use the "yargs" module.
Step 1:
npm install yargs
Step 2:
vi test.js
press i and copy the below code and paste it.
'use strict';
const args = require('yargs').argv;
console.log('Name: ' + args.name);
console.log('Age: ' + args.age);
Step 3 : Execution
node test.js --name=jacob --age=45
Step 4: output
Name: jacob
Age: 45
Let me know if it helps.

npm install return: mongodb is not in the npm registry

I'm beginner in nodeJs I want to install the environment to make login page with mongodb,
I create this package.json:
{
"name": "loginapp",
"version": "1.0.0",
"description": "simple app",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "test test",
"license": "ISC",
"dependencies":{
"bcryptjs":"*",
"body-parser":"*",
"connect-flash":"*",
"cookie-parser":"^1.4.1",
"express":"*",
"express-handlebars":"*",
"express-messages":"*",
"express-session":"*",
"express-validator":"*",
"mongobd":"*",
"mongoose":"*",
"passport":"*",
"passport-http":"*",
"passport-local":"*"
}
}
and when I wanted to install with npm install I found this error :
img-error
thank's for helping ..

Resources