Can't locate a file in Node.js - node.js

I am new to Node.js and while following one of the tutorials at tutorialspoint http://www.tutorialspoint.com/nodejs/nodejs_callbacks_concept.htm
I tried to run one simple program, but I am unable to run it successfully
var fs = require("fs");
var data = fs.readFileSync('./input.txt');
console.log(data.toString());
console.log("Program Ended");
This is the error message which I get:
C:\Users\Jack\Desktop\Nodee>node main.js
fs.js:549
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^
Error: ENOENT: no such file or directory, open 'C:\Users\Jack\Desktop\Nodee\input.txt'
at Error (native)
at Object.fs.openSync (fs.js:549:18)
at Object.fs.readFileSync (fs.js:397:15)
at Object.<anonymous> (C:\Users\Jack\Desktop\Nodee\main.js:3:15)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
Here is the Screenshot of my folder inside my desktop
http://i.imgur.com/O6Bi1qc.png
I have used this path but it failed as well:
C:\Users\Jack\Desktop\Nodee

Related

my npm refused to install and i entered "npm config unsafe-perm true" and now i receive this error when trying to install

node:fs:723
handleErrorFromBinding(ctx);
^
Error: EIO: i/o error, read
at Object.readSync (node:fs:723:3)
at tryReadSync (node:fs:433:20)
at Object.readFileSync (node:fs:471:19)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1120:18)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object. (C:\Program Files\nodejs\node_modules\npm\lib\utils\exit-handler.js:4:22)
at Module._compile (node:internal/modules/cjs/loader:1103:14) {
errno: -4070,
syscall: 'read',
code: 'EIO'
}

When I write "npm start" terminal is showing bindings error

this is the error i get after running npm start
> tictactoe#0.1.0 start
> parcel index.html
D:\courses\TicTacToe\node_modules\bindings\bindings.js:126
err = new Error(
^
Error: Could not locate the bindings file. Tried:
→ D:\courses\TicTacToe\node_modules\deasync\lib\binding\node-v93-win32-x64\deasync.node
at bindings (D:\courses\TicTacToe\node_modules\bindings\bindings.js:126:9)
at Object.<anonymous> (D:\courses\\TicTacToe\node_modules\deasync\index.js:30:31)
at Module._compile (D:\courses\TicTacToe\node_modules\v8-compile-cache\v8-compile-cache.js:192:30)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (D:\courses\TicTacToe\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
at Object.<anonymous> (D:\courses\TicTacToe\node_modules\parcel\src\utils\syncPromise.js:1:79)
at Module._compile (D:\courses\TicTacToe\node_modules\v8-compile-cache\v8-compile-cache.js:192:30) {
I tried installed npm again, but same error.

Node App - ReferenceError: uriUtil is not defined

I was workign on a Node App a few weeks ago which worked fine. I went to restart it today and its throwing this error
var mongooseUri = uriUtil.formatMongoose(mongodbUri);
^
ReferenceError: uriUtil is not defined
at Object.<anonymous> (d:\A\B\C\Web Applications\Donations1\routes\donations.js:14:19)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (d:\A\B\C\Web Applications\Donations1\app.js:9:17)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:139:18)
at node.js:999:3
It relates to this line of code that connects to mongodb
var mongodbUri = 'mongodb://AAA:BBB#ds053305.mongolab.com:12345/donations';
var mongooseUri = uriUtil.formatMongoose(mongodbUri);
You can replace this line:
var mongooseUri = uriUtil.formatMongoose(mongodbUri);
Which this line:
var mongooseUri =require('mongodb-uri').formatMongoose(mongodbUri);
Don't worry to require same module more than once. Node always require only one time, and after that use the cache for loading the module.

Getting type error with Sequelizejs

Im getting the following error and I can't figure out through the stack trace where it's erroring.
/Users/rahulsharma/Desktop/Jobletics/node_modules/sequelize/lib/sequelize.js:298
this.importCache[path] = defineCall(this, DataTypes)
^
TypeError: object is not a function
at module.exports.Sequelize.import (/Users/ra/Desktop/Js/node_modules/sequelize/lib/sequelize.js:298:32)
at db.sequelize (/Users/ra/Desktop/Js/models/index.js:14:33)
at Array.forEach (native)
at Object.<anonymous> (/Users/ra/Desktop/Js/models/index.js:13:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
Here is the git:
https://github.com/rahul1346/jb
Any idea?
business_model.js is an empty file.

Invoke the process.addListener() and Node tell me: No such module

I am newbie and I am writing a simple program based Node.js.
everything is fine until I added this line:
process.addListener('SIGINT', function(){ console.log( 'Sigint test.' ); } );
Run: Node sample.js
I got following message:
node.js:203
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: No such module
at EventEmitter.<anonymous> (node.js:361:27)
at Object.<anonymous> (D:\Nodejs\MySample\sample.js:13:9)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
at Array.<anonymous> (module.js:470:10)
at EventEmitter._tickCallback (node.js:195:26)
Environment:
Windows XP sp2
Node.js 0.5.9 for Windows
help me please...

Resources