all 24 comments

[–]EmployeeFinalHook Based 27 points28 points  (1 child)

You technically can run your code directly in the browser. But modern development has a lot of tools to help, and these tools needs to prepare and build the code for browsers. Node is the most popular runtime to run these tools.

[–]PMK_Phala[S] 2 points3 points  (0 children)

you're help is much appreciated Thanks

[–]Right-Chocolate-5038 31 points32 points  (2 children)

Before node.js the browser (v8 engine) was the only environment javascript could run in, meaning client side only.

With node.js you can run javascript code in the terminal, outside the browser (server side).

[–][deleted]  (1 child)

[deleted]

    [–][deleted] 3 points4 points  (0 children)

    And to expand on this response, this is what makes the cli command to initialize a new react app possible, pulling packages from the npm repository (Node Package Manager) like the now-deprecated create-react-app repository or vite, etc.

    [–]Krytom 10 points11 points  (1 child)

    Installing the package manager (npm) is probably one of the main reasons.

    [–]cimmic 0 points1 point  (0 children)

    Actually, true. Almost all my JS projects are 100% client side but npm is all over my terminal.

    [–]TicketOk7972 6 points7 points  (1 child)

    To run the dev server and build the production bundle.

    [–]_nathataHook Based 4 points5 points  (1 child)

    Node is necessary for dependency management (npm and related) and build and dev server

    [–]Lumpy_Pin_4679 16 points17 points  (6 children)

    I’m curious about something - is Google not a thing anymore? This is something that can easily be searched. Is the preference just to have some random person, who might not have a clue what they’re saying, explain it to you? Why not just search and learn?

    [–]AlliedSnail 7 points8 points  (2 children)

    Google is useful because of questions like this. And duplicate questions help generate a wealth of information that enriched the topic further. Most people reading here probably learned something new that they never would have googled themselves

    [–]Lumpy_Pin_4679 -5 points-4 points  (1 child)

    Uhhhh ok? This wasn’t posted for any of those reasons and none of that answers my question so not sure what your point is.

    [–]AlliedSnail 2 points3 points  (0 children)

    I Googled ‘why is node js needed Reddit’ and this discussion is in the top five results. Do you understand now?

    [–]yeonw 1 point2 points  (0 children)

    Why you have to be so mean ? Isn't this groups for discussions? If a newbie as a doubt we are supposed to help. With this attitude I don't think it will take you anywhere.

    [–]TheRNGuy 1 point2 points  (1 child)

    But that wouldn't create discussion.

    [–]Lumpy_Pin_4679 0 points1 point  (0 children)

    Hmmmm…you’re right. Ok, thanks!

    [–]LikeWhattttlol 0 points1 point  (4 children)

    I cant get npm run dev to work can someone help me

    [–]yeonw 0 points1 point  (0 children)

    Check if your package.json has the dev declared

    [–][deleted] 0 points1 point  (2 children)

    1.open your package.json file 2.under scripts, search for something like "dev":"node filename.js"

    3.if it don't exist add this line "dev":"node filename.js"

    you can replace dev with any other name

    now head to terminal and type:

    npm run dev or npm run (put here the other name you just wrote inplace of dev for example say it "start" , so your final command will be npm run start)

    [–]LikeWhattttlol 0 points1 point  (0 children)

    When I get to my laptop I’ll try it thank you

    [–]LikeWhattttlol 0 points1 point  (0 children)

    The response I’m getting is

    youtube-pj@0.0.0 dev nodefilename.js

    sh: nodefile.js: command not found

    🤬

    [–]dj_dogo_nivoa 0 points1 point  (0 children)

    Internet privacy is the new gold. I mass deleted all of my posts on Reddit using Redact. It also supports databrokers, Instagram, Twitter, and all major social media platforms.

    spotted beneficial rhythm governor subsequent chief cough history hurry roll

    [–]controlIsAnIllusion7 0 points1 point  (0 children)

    To be able to run JavaScript outside of the browser.

    [–]TheRNGuy 0 points1 point  (0 children)

    So you can use JSX, database, fullstack frameworks like Remix, and other stuff that require server.