I covered setting up a simple HTTP server using Node.js previously, but that was using the package “http-server” for serving files.
Today I hit the point of needing to write server-side code, so my approach had to change.
Follow these steps to get up and running asap:
- Install Node.js if you haven’t already
- Open your shell of choice (Terminal, Bash, Command Prompt, etc.)
- “cd” to your Project folder
- If you don’t have a “package.json” file, run “npm init” and mash Enter
- Run “npm install express –save” (dash dash save, sorry for WordPress formatting)
- Copy and paste the code below into a new file “server.js”
- Run “node server.js”