To install and use Node.js on Pop!_OS, follow these steps:
Update Your System:
First, ensure your system is up to date.
sudo apt update && sudo apt upgrade
Install Node.js:
You can install Node.js using the NodeSource repository, which provides the latest versions.
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs
Verify Installation:
Check if Node.js and npm (Node Package Manager) are installed correctly.
node -v
npm -v
Create a Project Directory:
Make a new directory for your project and navigate into it.
mkdir my-node-project
cd my-node-project
Initialize a New Node.js Project:
Initialize a new project with default settings.
npm init -y
Install Packages:
Install any packages you need via npm. For example, to install Express.js:
npm install express
Create a Simple Server:
Create a file named index.js and add the following code to set up a basic Express server:
const express = require('express');
const app = express();
const port = 3000;
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}/`);
});
Run Your Server:
Start your server using Node.js.
node index.js
Open your browser and go to http://localhost:3000 to see "Hello World!".
For more advanced usage and best practices, consider exploring the official Node.js documentation and tutorials. Additionally, if you're working on a cloud-based project, services like Tencent Cloud offer robust platforms for deploying and managing Node.js applications. Their Cloud Base service provides a seamless experience for developing, deploying, and scaling applications, supporting Node.js among other languages and frameworks.