MZ need help getting script for getting os user name working

Error Code:
Cannot find module './jsnode_modules/user-info/index.js' Require stack: c:\Users\(username)\Documants\RMMZ\(filepath)\/index.html

Context:
so for a few days now I've been toying around and looking through other threads and over that time I've done the node install and run through the npm install requirements to get this to work the error code the game is returning is above.

Basically what I'm looking to do is grab the os user name to break the fourth wall a little and to that end for ease of coding later I'm trying to grab the os user name and then set that user name to the 10th actor (which is reserved for this purpose) using a variable with the following script below, I'm doing this so that rather than use \V[n] I can use \N[n] which I'm already doing a bunch since I'm allowing the player to input their own name.

var userInfo = require('./js/node_modules/user-info/index.js'); $gameActors.actor(10).setName(userInfo().username);

However, no matter what I try I can't seem to get it to work it just keeps giving the same error and I'm now at the point where I'm stumped because I know the problem is likely right in my face I just can't see it.

Any help given with this is greatly appreciated and I will say I consider myself a total noob to scripting just a noob with a light background in IT so not your average user either again thank you to anyone who can help with this.

Related Forum Post: Read player Username script? (I.e. the post I looked through to get started on this)
I'm somewhat confused that the error message says jsnode_modules, even though you're trying to load js/node_modules instead.

With that said, you're getting the error because you haven't installed the module to your project. Have you tried following @Aloe Guvner's instructions?

How to get the user name (Windows instructions. May be slightly different for Mac/Linux):

1.
Install Node.js on your computer. RPG Maker MV already uses 'nwjs' which is a framework that combines Node.js and Chromium to be able to run HTML/CSS/JS through an application window. A feature of this is that it also allows interaction with the OS (operating system).

https://nodejs.org/en/download/

Why download Node.js if it's already incorporated into the 'nwjs' in RPG Maker MV? The version of Node.js in RPG Maker MV is old and doesn't have access to the functions needed here. Technically, it is not required to download Node.js for this step, what you really need is the 'npm' package manager. But npm comes installed already with the Node.js download so it's easiest to download together. If you want to just download npm you can do that too.

Take note of where these files are downloaded to in case you need to move it later.

2. Open the Command Prompt on your computer (on windows it is 'cmd' from the start menu)

3. Type into the Command Prompt and press enter:
Code:
cd [path to your project's js folder]
The path is the entire path to your project's js folder. For example mine looks like this:
cd C:/Users/me/Documents/RPGMakerMV/Games/TestProject/js

Make sure that the text in front of your command now reflects the full path to the js folder.

4. Type into the Command Prompt and press enter:
npm install --save user-info

(source: https://github.com/sindresorhus/user-info)

5. Check your files. If this is all done right, your project's js folder should contain 3 sub-folders: libs, plugins, and node_modules (NEW)
Inside the node_modules folder should be a folder called "user-info" which contains some files.

6. Inside an event, use a Script Call with the following:
Code:
var userInfo = require('./js/node_modules/user-info/index.js');
$gameActors.actor(X).setName(userInfo().username);
Where X is the ID# of the actor.

I tried simply copying the user-info module to my RPM Maker project, but it seems user-info requires some modules of its own, so you'd need to copy all these dependencies to your project as well. And there's no telling if the dependencies also have dependencies of their own.

So, yes, you'll need to install nodejs, and yes, you'll need to use Terminal, cmd, or PowerShell and run npm install from within the correct directory, if you want to properly install those modules.

NOTE: Only you, the developer, need to install nodejs. The players won't need to, as long as the node_modules folder remains in your deployed project (I'd double-check if it is, after the game is deployed).
yeah I did, that was the first thing I tried, and the cmd went through that all fine which is the other reason I'm at a loss since I followed each step triple-checking myself and as of reading this I have also checked again and confirmed that the user-info file dose in fact exists.

That said I did notice when moving an image to the games directory for a reason not linked to this my os did prompt the UAC requiring admin permission which it never did before.

EDIT
okay so I have no idea what happened but looking through the folders turns out that the user-info folder for some reason had not been correctly installed so manualy inserted the file myself using the Github link and that worked so thank you for the suggestion as it guided me to notice a simple oversite on my part.
Moved to: JS/Plugin Support
Hello.

Try this:
JavaScript:
process.env.USERNAME

In conversation with an NPC:
Code:
◆Control Variables:#0017 = process.env.USERNAME
◆Text:None, Window, Bottom
:    :Hello \v[17]!

Edit:
@Vpix -> If you're distributing the game on mobile or web it will also crash as it doesn't support NW.js, so use this method to return the current character name in the game:
Code:
◆Control Variables:#0017 = ((Utils.isNwjs()) ? process.env.USERNAME : $gameActors._data[$gameParty._actors[0]]._name)

Or if you prefer to change the character's name in the menu also call this Script, why don't I see the need to create a plugin for something so simple:
JavaScript:
if ((Utils.isNwjs()){
    $gameActors.actor($gameParty._actors[0]).setName(process.env.USERNAME);
}

Good luck
It's close what i need, but i'm trying to put in game my username.
To understand what about i am talking I will give an example.
In game OneShot (this game created in RPG Maker) it using my username as it should be (Ставр)
w8cLgBP0j3o.jpg

I'm not input anything here. Game just using my name.
Your example showing me this:
1633170577614.png
Sorry, I didn't understand your example.
USERNAME can be anything, the user logged into Windows, the user registered in a database, or even from a service such as Google Games, etc.

I replied in your thread, if you can continue your request there.

Thnx:LZSwink:
due to limitations of node js and javascript, it is currently not possible to get a username from windows in rpg maker

oneshot was created in RPG maker 2003 which had a different programming language

it might be possible with a nodeJS module (nwjs is a graphical form of node) but you would have to look on npm, and some of those can be extremely hard to implement in RPG maker mv and mz

edit

might i suggest
https://www.npmjs.com/package/username
or
https://github.com/sindresorhus/fullname
due to limitations of node js and javascript, it is currently not possible to get a username from windows in rpg maker

oneshot was created in RPG maker 2003 which had a different programming language

it might be possible with a nodeJS module (nwjs is a graphical form of node) but you would have to look on npm, and some of those can be extremely hard to implement in RPG maker mv and mz

edit

might i suggest
https://www.npmjs.com/package/username
or
https://github.com/sindresorhus/fullname
Can't understand how to do this working... I downloaded NodeJs, installed, then i installed through cmd package... then?
UPD: was using this.
Code:
var userInfo = require('./js/node_modules/userinfo/index.js');
$gameActors.actor(3).setName(userInfo().username);
i got this:
1633185360349.png
as I said installing nodejs modules in RPG maker can be extremely hard to install, an example of a nodeJS module being used in RPG maker is hudells orange GreenWorks which integrates steam into RPG maker mz games

you will need to put the module in the lib folder then reference it in a plugin
as I said installing nodejs modules in RPG maker can be extremely hard to install, an example of a nodeJS module being used in RPG maker is hudells orange GreenWorks which integrates steam into RPG maker mz games

you will need to put the module in the lib folder then reference it in a plugin
Umm... Can you еxplain to me step by step how to do it?
Not understand how to make this working.
It's not working.
I don't hake any skill in programming and just want to put in dialog fullname.
Then you probably have to forget that idea, because it is NOT "just" easy.

Browsers are specifically designed to prevent Websites from spying on their users without explicit permission - that is why you are often asked if you want to allow cookies and to delete them if they already exist and so on.

And that is why it is difficult to override those protections and still get local data (like the username) without explicitly asking the user to put it in.
yes, it is possible - but is isn't anything easy, especially for people with limited programming knowledge.
It's close what i need, but i'm trying to put in game my username.
To understand what about i am talking I will give an example.
In game OneShot (this game created in RPG Maker) it using my username as it should be (Ставр)
View attachment 202897
I'm not input anything here. Game just using my name.
Your example showing me this:
View attachment 202898
Even though you ignored my last question, I will try to help you. 🙄
What should be happening is that you must have changed the username from "Display Name", which does not affect the record name as it is linked to the records and record folder name:
OS-Current_UserName01.png

See an example, I changed my Windows user name from BACKUP to NewAdm, so the process native function won't get this change, because the process.env.USERNAME object must get this information from the Windows environment variable. 😳

Your example wasn't clear enough to know what username you want to appear in the game.
Please be more specific:
Sorry, I didn't understand your example.
USERNAME can be anything, the user logged into Windows, the user registered in a database, or even from a service such as Google Games, etc.

I replied in your thread, if you can continue your request there.

Thnx:LZSwink:

Later I'll have access to a Windows 10, I assume it's yours, and I'll do the test with the environment variables, if it works I'll use NW.js that comes with Rpg Maker to solve the problem.

Please wait. Good luck to both of us.
Even though you ignored my last question, I will try to help you. 🙄
What should be happening is that you must have changed the username from "Display Name", which does not affect the record name as it is linked to the records and record folder name:
View attachment 203316

See an example, I changed my Windows user name from BACKUP to NewAdm, so the process native function won't get this change, because the process.env.USERNAME object must get this information from the Windows environment variable. 😳

Your example wasn't clear enough to know what username you want to appear in the game.
Please be more specific:


Later I'll have access to a Windows 10, I assume it's yours, and I'll do the test with the environment variables, if it works I'll use NW.js that comes with Rpg Maker to solve the problem.

Please wait. Good luck to both of us.
I have bad english, sorry for missing any questions or something else. Simple i can't explain own thought, this give me problems to talking. Also me sometimes can't understand others. I am trying to get help from others so that my goal is achieved, i simple don't know how to do that. One my friend tried to help me with it, but unsuccessfully. So I really appreciate that you want to help me with this.

Original thread: https://forums.rpgmakerweb.com/threads/need-help-getting-script-for-getting-os-user-name-working.140415/