Yes, Sublime Text provides support for Node.js. So we can run nodejs app in Sublime Text.
-
Install Sublime Text:
- Install Sublime Text using official apt repository (or you can say Install GPG key):
wget -qO – https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add – - Add the apt repository (Stable or Dev), we are using stable:
echo “deb https://download.sublimetext.com/ apt/stable/” | sudo tee /etc/apt/sources.list.d/sublime-text.list - Check updates:
sudo apt-get update - Install sublime-text:
sudo apt-get install sublime-text - Verify whether Sublime Text is installed properly using the following command:
subl –version
- Install Sublime Text using official apt repository (or you can say Install GPG key):
-
Install Node.js:
- Run the following command to install the Node.js package:
sudo apt install nodejs - Set variable path using following command if not set:
ln -s /usr/bin/nodejs /usr/bin/node - Verify whether Node.js is installed properly using the following command:
node –version
The output should be like this: - Now install the Node Package Manager(npm), using the following command:
sudo apt install npm - Verify whether npm is installed properly using the following command:
npm –version
The output should be like this:
- Run the following command to install the Node.js package:
-
Make changes in Sublime Text settings as mentioned below to run Node.js in Sublime Text:
- Open the Command Palette in Sublime Text using:
Cmd+Shift+P - Type (for “Package Control: Install Package”):
pkgctlinspkg - Type:
Nodejs - Nodejs will be listed click on it to install.
- Go to Preferences -> Package settings -> nodejs -> settings user
- Now change the value of “node_command”: false, to “node_command”: “/usr/local/bin/node”
- Open the Command Palette in Sublime Text using:
-
Write a nodejs hello world program, save the file & build it to run it in sublime text.
- Create a server.js file write the following code & save the file.
var http = require("http");
http.createServer(function (request, response) {
// Send the HTTP header
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});
// Send the response body as "Hello World"
response.end('Hello World\n');
}).listen(8081);
// Console will print the message
console.log('Server running at http://127.0.0.1:8081/'); - Press Ctrl+B to build the node js file. Now you can see in sublime text node js server has started.
- Create a server.js file write the following code & save the file.
If you need to prove your skills in the .NET framework, get .NET certified on StudySection. StudySection provides .NET Certification Exam for beginners as well as experts in the .NET framework. This .NET certification can improve your resume’s success rate.