How To Host A Local Node.js Website

June 11, 2024

Needs:

  • NodeJs - Install Using the website or choco

Run This Command:

npx create-next-app@latest

This would be showing this prompts

What is your project named? my-app
Would you like to use TypeScript? No / Yes
Would you like to use ESLint? No / Yes
Would you like to use Tailwind CSS? No / Yes
Would you like to use `src/` directory? No / Yes
Would you like to use App Router? (recommended) No / Yes
Would you like to customize the default import alias (@/*)? No / Yes
What import alias would you like configured? @/*

I have encountered an error that is same to this where if would not allow me to run a script command to it need to allow it through by running the power shell in administrator and running this command

Set-ExecutionPolicy RemoteSigned

You can also run it in the default power shell but you need would encounter this error.

Access to the registry key
'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied. 
To change the execution policy for the default (LocalMachine) scope, 
  start Windows PowerShell with the "Run as administrator" option. 
To change the execution policy for the current user, 
  run "Set-ExecutionPolicy -Scope CurrentUser".

To fix this we need to run this.

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

Running the Website (Locally)

To start the website locally we just need to simply run this command in the terminal of your next.js directory

npm run dev

This would appear (based on your computer's information)

PS C:\Users\ewanm\Documents\Website\logic-labs> npm run dev

> logic-labs@0.1.0 dev
> next dev

   Next.js 14.2.3
  - Local:        http://localhost:3000

  Starting...
  Ready in 1880ms
(node:14364) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
  Compiling / ...
  Compiled / in 2.3s (532 modules)
 GET / 200 in 2481ms
  Compiled in 189ms (250 modules)
 GET / 200 in 61ms

And there you go you have a working local Node.js website running.