DEV Community

Discussion on: exe closes immediately

Collapse
 
katnel20 profile image
Katie Nelson

Looks like you missed a path parameter somewhere.

Collapse
 
lund8888 profile image
lund8888 • Edited

Hi, thank you for your message. I m running the file from this path
C:\Users\myname\Documents\Node_apps\internet\example_exec> prettyprint.exe

this is my main.js , I simply pasted the code:

module.exports = filePath => JSON.stringify(JSON.parse(require('fs').readFileSync(filePath).toString()), false, 3)
var http = require('http');
var server= http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8124);

console.log('Server running at 127.0.0.1:8124/');
server.setTimeout(100000);

Unless you mean that the path should be specified like this in the main.js,
module.exports = function(C:\Users\myname\Documents\Node_apps\internet\example_exec) {
I thought it is generic.

This is the bin.js:

const prettyprint = require('.') /* the current working directory so that means main.js because of package.json /
let theFile = process.argv[2] /
what the user enters as first argument */
console.log(
prettyprint(theFile)
)
console.log(require('.')(process.argv[2]))

This is the package.json:

{
"name": "prettyprint",
"version": "0.0.1",
"description": "Pretty print a JSON file.",
"main": "main.js",
"bin": "bin.js",
"author": "anybody",
"license": "MIT"
}

There is no mistake at the path, the path of the terminal is correct

Do you see the attachment of the path I uploaded?
All the files are in : C:\Users\myname\Documents\Node_apps\internet\example_exec
The folder contains:
bin.js
main.js
package.json
prettyprint.exe