How do you run a js file using npm scripts?

0 votes

I can't get npm to work. My package.json file has

"scripts": { "build": "build.js" }

and I have a build.js file in the same folder that just console.logs.

When I run

npm run build

I get the error

The system cannot execute the specified program.

npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
npm ERR! node v4.1.1
npm ERR! npm  v3.3.5
npm ERR! code ELIFECYCLE

and if I move the build.js file and change my package.json file to have a subfolder

"scripts": { "build": "build/build.js" }

then I get the error

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

What's going wrong?

Oct 11 in Node-js by kartik
• 35,820 points
394 views

1 answer to this question.

0 votes

Hello @kartik,

Try this:

{ "scripts" :
  { "build": "node build.js"}
}

npm run build OR npm run-script build
{
  "name": "build",
  "version": "1.0.0",
  "scripts": {
    "start": "node build.js"
  }
}

npm start

Hope it helps!!
Thank you!!

answered Oct 11 by Niroj
• 78,120 points

Related Questions In Node-js

0 votes
1 answer

How do you log content of a JSON object in Node.js?

Hello @kartik, Try this one: console.log("Session: %j", session); If the ...READ MORE

answered Jul 16 in Node-js by Niroj
• 78,120 points
51 views
0 votes
1 answer

How do I uninstall a package installed using npm link?

Hello @kartik, The package can be uninstalled using ...READ MORE

answered Jul 16 in Node-js by Niroj
• 78,120 points
165 views
0 votes
1 answer

How to download a file with Node.js without using third-party libraries?

Hii, You can create an HTTP GET request and pipe ...READ MORE

answered 2 days ago in Node-js by Niroj
• 78,120 points
11 views
0 votes
1 answer

How do I test a single file using Jest?

Hii, All you have to do is chant ...READ MORE

answered 1 hour ago in Node-js by Niroj
• 78,120 points
2 views
0 votes
1 answer

jQuery AJAX fires error callback on window unload - how do I filter out unload and only catch real errors?

Hello, In the error callback or $.ajax you have three ...READ MORE

answered Apr 27 in Java-Script by Niroj
• 78,120 points
448 views
0 votes
1 answer

How do I pass command line arguments to a Node.js program?

Hello @kartik, If your script is called myScript.js ...READ MORE

answered May 5 in Java-Script by Niroj
• 78,120 points
697 views
0 votes
1 answer

Error:Issue when trying to use IN() in wordpress database

Hello @kartik, Try this code : // Create an ...READ MORE

answered May 8 in PHP by Niroj
• 78,120 points
91 views
+2 votes
1 answer

How do I debug Node.js applications?

Hello @kartik, Use node-inspector  from any browser supporting WebSocket. Breakpoints, ...READ MORE

answered Jul 8 in Node-js by Niroj
• 78,120 points
87 views
0 votes
1 answer

How do you reinstall an app's dependencies using npm?

Hello @kartik, The easiest way is  to delete node_modules folder ...READ MORE

answered Jul 12 in Node-js by Niroj
• 78,120 points
255 views
0 votes
1 answer

How do I install a module globally using npm?

Hello @kartik, I found the output contained the ...READ MORE

answered Jul 16 in Node-js by Niroj
• 78,120 points
56 views